← Back to Configuration | ← Back to Documentation
WebSSH2 supports multiple configuration methods with a clear priority order, following the 12-Factor App methodology.
Configuration is loaded with the following priority (highest to lowest):
- Environment Variables (highest priority)
- config.json file
- Built-in defaults (lowest priority)
This means environment variables always override config.json settings, which in turn override defaults.
| Method | Best For | Pros | Cons |
|---|---|---|---|
| Environment Variables | Production, Docker, K8s | Secure, 12-factor compliant, no file management | Can be verbose for complex configs |
| config.json | Development, complex configs | Easy to read, supports comments, version control | Requires file management, less secure |
| URL Parameters | Per-connection customization | Dynamic, user-specific | Limited scope, visible in logs |
# Basic configuration
export WEBSSH2_LISTEN_PORT=3000
export WEBSSH2_SSH_HOST=default.ssh.server
export WEBSSH2_HEADER_TEXT="Production WebSSH2"
# Start the server
npm start{
"listen": {
"port": 3000
},
"ssh": {
"host": "default.ssh.server"
},
"header": {
"text": "Production WebSSH2"
}
}http://localhost:2222/ssh?port=22&header=Development
All WebSSH2 environment variables follow a consistent naming pattern:
WEBSSH2_<SECTION>_<SUBSECTION>_<SETTING>
Examples:
WEBSSH2_LISTEN_PORT→listen.portWEBSSH2_SSH_ALGORITHMS_KEX→ssh.algorithms.kexWEBSSH2_SESSION_COOKIE_SECRET→session.cookie.secret
# Enable debugging
export DEBUG="webssh2:*"
export WEBSSH2_LISTEN_PORT=3000
export WEBSSH2_HTTP_ORIGINS="http://localhost:*"
npm run devENV WEBSSH2_LISTEN_PORT=2222
ENV WEBSSH2_SSH_ALGORITHMS_PRESET=modern
ENV WEBSSH2_SESSION_SECRET="strong-random-secret"
ENV WEBSSH2_HTTP_ORIGINS="https://yourdomain.com"
ENV WEBSSH2_LOG_LEVEL=infoapiVersion: v1
kind: ConfigMap
metadata:
name: webssh2-config
data:
WEBSSH2_LISTEN_PORT: "2222"
WEBSSH2_SSH_HOST: "bastion.internal"
WEBSSH2_HEADER_TEXT: "K8s WebSSH2"
WEBSSH2_HTTP_ORIGINS: "https://*.yourdomain.com"Controls how the WebSSH2 server runs:
- Listen address and port
- SSL/TLS settings
- Logging configuration
SSH connection defaults and algorithms:
- Default host and port
- Algorithm presets (modern, legacy, default)
- Authentication methods
- Environment variable forwarding
Web session management:
- Session secret
- Cookie settings
- Timeout values
User interface customization:
- Header text and styling
- Terminal defaults
- Theme settings
Security-related settings:
- CORS origins
- SSO integration
- HTTPS enforcement
# Good: Secure, no files to manage
export WEBSSH2_SESSION_SECRET="${SECRET_FROM_VAULT}"
# Avoid: Secrets in files
echo '{"session":{"secret":"hardcoded"}}' > config.jsonAlways validate your configuration:
# Check environment variables
env | grep WEBSSH2_
# Test configuration loading
DEBUG=webssh2:config npm startInstead of configuring individual algorithms:
# Good: Use preset
export WEBSSH2_SSH_ALGORITHMS_PRESET=modern
# Avoid: Manual algorithm configuration (unless needed)
export WEBSSH2_SSH_ALGORITHMS_KEX="curve25519-sha256,..."# Use secret management
export WEBSSH2_SESSION_SECRET="$(vault read -field=secret secret/webssh2)"
# Never commit secrets
echo "config.json" >> .gitignoreCreate a .env.example file:
# .env.example
WEBSSH2_LISTEN_PORT=2222
WEBSSH2_SSH_HOST=ssh.example.com
WEBSSH2_SESSION_SECRET=change-this-secret
WEBSSH2_HTTP_ORIGINS=https://yourdomain.comOld (config.json):
{
"listen": {
"port": 3000
},
"ssh": {
"host": "ssh.example.com",
"port": 22
}
}New (Environment Variables):
export WEBSSH2_LISTEN_PORT=3000
export WEBSSH2_SSH_HOST=ssh.example.com
export WEBSSH2_SSH_PORT=22See Breaking Changes for migration details.
WebSSH2 validates configuration on startup:
- Type checking - Ensures correct data types
- Range validation - Checks port numbers, timeouts
- Format validation - Validates URLs, email addresses
- Dependency checking - Ensures related settings are compatible
Invalid configuration will prevent startup with clear error messages.
- Check environment variable names (must start with
WEBSSH2_) - Verify config.json location (
./config.json) - Enable debug mode:
DEBUG=webssh2:config npm start
Remember the priority order:
- URL parameters (for applicable settings)
- Environment variables
- config.json
- Defaults
Environment variables are strings. WebSSH2 automatically converts:
"true"/"false"→ boolean"123"→ number'["a","b"]'→ array'{"a":"b"}'→ object