This is a simple SSH server implementation using the gliderlabs/ssh library with timeout functionality.
. ├── main.go ├── main_test.go ├── go.mod ├── go.sum └── README.md
go build -o solo
# Run with default settings (0.0.0.0:8822)
./solo
# Run with custom address
./solo -addr "127.0.0.1:2222"
# Run with custom timeouts
./solo -max-timeout=60s -idle-timeout=20s
# Run with agent forwarding disabled
./solo -enable-agent=false
# Run with PTY terminal support disabled
./solo -enable-pty=false
# Run with a custom authorized keys file
./solo -publickey-file="/path/to/authorized_keys"
# Run in daemon mode (background)
./solo -daemon
# Run with debug mode
./solo -debug
# Use environment variables
SOLO_ADDR="127.0.0.1:2222" SOLO_MAX_TIMEOUT=60s SOLO_IDLE_TIMEOUT=20s SOLO_ENABLE_AGENT=false SOLO_ENABLE_PTY=false ./solo
By default, the server looks for an authorized keys file at $HOME/.config/solo/authorized_keys.
If this file doesn't exist, the server will create the directory structure automatically.
You can override this location using the -publickey-file flag or the SOLO_PUBLICKEY_FILE environment variable.
go test -v
Once the server is running, you can connect to it using any SSH client:
ssh username@localhost -p 8822
This will start an interactive shell session. If PTY is enabled (default), you'll get a fully interactive terminal.
ssh username@localhost -p 8822 "ls -la"
This will execute the specified command and return the output. The server properly handles exit codes for commands.
If SFTP is enabled (default), you can also connect using SFTP:
sftp -P 8822 username@localhost
max-timeout: Maximum duration for a connection (default: 3000s)idle-timeout: Timeout for idle connections (default: 300s)When a connection exceeds these limits, it will be automatically closed by the server.
enable-agent: Enable SSH agent forwarding (default: true)When enabled, the server will forward SSH agent connections if requested by the client. This allows clients to use their local SSH keys for authentication with other servers.
To test agent forwarding, you can use the SSH client with the -A flag:
ssh -A -p 8822 username@localhost
Once connected, you can verify that agent forwarding is working by checking if the SSH_AUTH_SOCK environment variable is set:
echo $SSH_AUTH_SOCK
You can also use ssh-add -l to list the keys loaded in your agent:
ssh-add -l
The server now fully supports both exec commands and shell sessions:
ssh user@host "ls -la"daemon: Run the server in the background as a daemon (default: false)When enabled, the server will fork itself to run in the background, redirecting all standard input/output to /dev/null. The parent process will print the PID of the daemon and exit.
enable-pty: Enable PTY terminal support (default: true)When enabled, the server will provide a PTY terminal when requested by the client. This allows clients to run interactive commands like bash, top, vim, etc. When a PTY is requested, the server launches bash in a pseudo-terminal for a full interactive shell experience.
MIT