A simple SSH server implementation in Go that supports both password and public key authentication, with full PTY (pseudo-terminal) support for interactive shell sessions.
- Dual Authentication: Supports both password-based and public key authentication
- PTY Support: Full pseudo-terminal support for interactive shell sessions
- Command Execution: Supports both interactive shells and direct command execution
- Window Resizing: Dynamic terminal window resizing support
- Exit Status: Proper SSH exit status reporting
- Session Management: Handles multiple concurrent SSH connections
- Go 1.25.1 or later
- SSH key pair (for key-based authentication)
If you don't have SSH keys, generate them:
ssh-keygen -t rsa -b 2048 -f id_rsa -N ""This will create:
id_rsa(private key for the server)id_rsa.pub(public key for client authentication)
go mod tidygo run main.goThe server will start listening on 0.0.0.0:2222.
The server configuration is defined in main.go:
const (
serverAddr = "0.0.0.0:2222" // Server address and port
allowedUser = "testuser" // Username for password auth
allowedPassword = "secret123" // Password for authentication
)- Username:
testuser - Password:
secret123
- Uses the public key from
id_rsa.pub - The corresponding private key must be used by the SSH client
ssh -p 2222 testuser@localhost
# Enter password: secret123ssh -i id_rsa -p 2222 testuser@localhostReplace localhost with your machine's IP address:
ssh -p 2222 testuser@192.168.1.36- Session Channels: Interactive shell sessions
- PTY Requests: Pseudo-terminal allocation
- Window Changes: Dynamic terminal resizing
- Shell Requests: Interactive shell spawning
- Exec Requests: Direct command execution
- Exit Status: Proper exit code reporting
- Default credentials are hardcoded
- No rate limiting or connection throttling
- No logging of authentication attempts
- No firewall or access control beyond basic authentication
github.com/creack/pty- PTY (pseudo-terminal) supportgolang.org/x/crypto- SSH protocol implementation
├── main.go # Main SSH server implementation
├── go.mod # Go module definition
├── go.sum # Dependency checksums
├── id_rsa # Server private key (generate if missing)
├── id_rsa.pub # Client public key for authentication
└── README.md # This file
- Ensure port 2222 is not in use by another process
- Check that
id_rsaprivate key file exists - Verify Go version compatibility
- For password auth: verify username is
testuserand password issecret123 - For key auth: ensure
id_rsa.pubexists and matches your client's private key - Check file permissions on key files
- Verify the server is running and listening on the correct port
- Check firewall settings if connecting from a remote machine
- Ensure you're using the correct IP address and port (2222)
This project is for educational purposes. Use at your own risk.