Overview
SSH Portfolio can be configured using environment variables to customize runtime behavior without modifying code or rebuilding the application.Available Environment Variables
SSH_PORT
Controls which port the SSH server listens on.The port number for the SSH server to bind to.
main.go:27-29):
Configuration Files
In addition to environment variables, SSH Portfolio uses configuration files:config.yaml
The application loadsconfig.yaml from the working directory (main.go:31-34):
SSH Host Keys
SSH host keys are loaded from a hardcoded path (main.go:38):
.ssh/id_ed25519 (relative to working directory)
Server Configuration
Host Address
The server binds to all interfaces by default (main.go:25):
0.0.0.0 (all interfaces)
Default Port
WhenSSH_PORT is not set, the server uses port 2222 (main.go:26):
2222
Address Binding
The host and port are combined using (main.go:37):
0.0.0.0:2222.
Configuration Examples
Development Setup
Run locally on a high port:Production Setup
Run on standard SSH port (requires root or capabilities):Docker Development
Map container port 22 to host port 2222:Docker Production
Run on standard SSH port:systemd Service
Configure via systemd unit file:Multiple Instances
Run multiple instances on different ports:Override Hierarchy
Configuration is loaded in this order:-
Code defaults - Hardcoded in
main.go- Host:
0.0.0.0 - Port:
2222 - Config file:
config.yaml - SSH keys:
.ssh/id_ed25519
- Host:
-
Environment variables - Override defaults
SSH_PORT- Overrides default port
- Command-line flags - Not currently implemented
Default Values Summary
| Setting | Default Value | Configurable | Method |
|---|---|---|---|
| Host | 0.0.0.0 | No | Hardcoded |
| Port | 2222 | Yes | SSH_PORT |
| Config file | config.yaml | No | Hardcoded |
| SSH key path | .ssh/id_ed25519 | No | Hardcoded |
Validation and Errors
Missing Configuration File
Ifconfig.yaml is not found:
config.yaml exists in the working directory.
Missing SSH Host Keys
If.ssh/id_ed25519 is not found, the server will attempt to generate keys automatically. If generation fails:
Invalid Port Number
IfSSH_PORT contains an invalid port:
Port Already in Use
If the port is already bound:Environment Files
Using .env Files
Create a.env file for local development:
direnv:
Docker .env File
Docker Compose automatically loads.env:
Security Considerations
Sensitive Values
While SSH Portfolio currently doesn’t use sensitive environment variables, follow these best practices:- Use restrictive file permissions:
chmod 600 .env - Store secrets in proper secret management systems
- Rotate SSH host keys periodically
- Monitor environment variable access in logs
Next Steps
Docker Deployment
Deploy with Docker
Manual Deployment
Deploy from source