SSH Config Generator
Generate SSH configuration entries for easier server connections.
About SSH Config Files
The SSH config file (~/.ssh/config) allows you to create shortcuts for SSH connections, eliminating the need to remember complex connection parameters. It's especially useful when managing multiple servers.
Benefits
- Simplicity: Connect with
ssh myserverinstead ofssh user@192.168.1.100 -p 2222 -i ~/.ssh/custom_key - Consistency: Always use the same settings for each server
- Productivity: Save time when connecting frequently
- Organization: Keep all connection details in one place
- Security: Specify different keys for different servers
Common Configuration Options
| Option | Description | Example |
|---|---|---|
Host |
Alias name for the connection | Host myserver |
HostName |
Real hostname or IP address | HostName 192.168.1.100 |
User |
Username to login as | User ubuntu |
Port |
SSH port (default: 22) | Port 2222 |
IdentityFile |
Path to private key | IdentityFile ~/.ssh/id_rsa |
ServerAliveInterval |
Keep connection alive (seconds) | ServerAliveInterval 60 |
ForwardAgent |
Enable SSH agent forwarding | ForwardAgent yes |
LocalForward |
Port forwarding | LocalForward 8080 localhost:80 |
Real-World Examples
Basic Server Connection
Host webserver
HostName 192.168.1.100
User deploy
IdentityFile ~/.ssh/webserver_key
Port 22
Connect with: ssh webserver
Jump Host (Bastion)
Host bastion
HostName bastion.example.com
User admin
IdentityFile ~/.ssh/bastion_key
Host internal-server
HostName 10.0.1.50
User ubuntu
ProxyJump bastion
IdentityFile ~/.ssh/internal_key
Connect through bastion: ssh internal-server
GitHub with Multiple Accounts
Host github-personal
HostName github.com
User git
IdentityFile ~/.ssh/github_personal
Host github-work
HostName github.com
User git
IdentityFile ~/.ssh/github_work
Clone with: git clone git@github-work:company/repo.git
Wildcards and Patterns
You can use wildcards to apply settings to multiple hosts:
Host *.example.com
User admin
IdentityFile ~/.ssh/example_key
Host 192.168.1.*
User root
Port 2222
Host *
ServerAliveInterval 60
ServerAliveCountMax 3
Security Best Practices
- File permissions: Set
chmod 600 ~/.ssh/config - Key permissions: Private keys should be
chmod 600 - Use SSH keys: Disable password authentication when possible
- Keep alive settings: Prevent connection timeouts
- Organize by purpose: Group related hosts together with comments
- Version control: Keep a backup of your config (remove sensitive data)
Quick Commands
Edit SSH config:
nano ~/.ssh/config
Set correct permissions:
chmod 600 ~/.ssh/config
Generate SSH key:
ssh-keygen -t rsa -b 4096
Copy key to server:
ssh-copy-id user@host
Test connection:
ssh -v hostname
List SSH keys:
ls -la ~/.ssh/
Troubleshooting
Connection refused:
- Check if SSH service is running
- Verify port number (default: 22)
- Check firewall rules
Permission denied:
- Check username
- Verify SSH key permissions (600)
- Ensure public key is in authorized_keys