SSH Troubleshooting Guide: Common Issues and Solutions
SSH issues can be frustrating when trying to connect to remote servers. Let’s explore common SSH problems and their solutions to help you get back on track quickly.
Common SSH Issues
1. Connection Refused
ssh: connect to host example.com port 22: Connection refused
Solutions:
- Verify the SSH service is running:
sudo systemctl status ssh # For Ubuntu/Debian sudo service sshd status # For RHEL/CentOS
- Check firewall settings:
sudo ufw status # Ubuntu sudo firewall-cmd --list-all # CentOS
- Confirm the correct port:
ssh -p PORT_NUMBER user@hostname
2. Permission Denied
Permission denied (publickey,password)
Solutions:
- Check key permissions:
chmod 600 ~/.ssh/id_rsa chmod 644 ~/.ssh/id_rsa.pub
- Verify key is added to agent:
ssh-add ~/.ssh/id_rsa ssh-add -l # List added keys
- Check authorized_keys file:
chmod 700 ~/.ssh chmod 600 ~/.ssh/authorized_keys
3. Host Key Verification Failed
WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!
Solutions:
- Remove old key (if you trust the change):
ssh-keygen -R hostname
- Update known_hosts manually:
ssh-keyscan -H hostname >> ~/.ssh/known_hosts
4. SSH Agent Issues
Solutions:
- Start SSH agent:
eval $(ssh-agent)
- Add key permanently (add to ~/.bashrc):
if [ -z "$SSH_AUTH_SOCK" ]; then eval $(ssh-agent -s) ssh-add fi
Best Practices
Key Management
- Use strong key encryption:
ssh-keygen -t ed25519 -a 100
- Backup your keys:
cp -r ~/.ssh/id_* /secure/backup/location/
Security Configuration
- Disable password authentication:
# In /etc/ssh/sshd_config PasswordAuthentication no
- Use specific user permissions:
# In /etc/ssh/sshd_config AllowUsers user1 user2
Performance Optimization
- Enable connection multiplexing:
# In ~/.ssh/config Host * ControlMaster auto ControlPath ~/.ssh/control:%h:%p:%r ControlPersist 1h
- Use compression for slow connections:
ssh -C user@hostname
Modern Alternatives
While SSH is powerful, modern cloud platforms offer simpler solutions. For example, Thunder Compute eliminates SSH complexity entirely, letting you directly connect to cloud instances with tnr connect
.
- No key management required
- Automatic security updates
- Zero-configuration setup
Debugging Tools
- Verbose logging:
ssh -vvv user@hostname
- Test connectivity:
nc -zv hostname 22
- Check SSH daemon logs:
sudo tail -f /var/log/auth.log # Ubuntu sudo tail -f /var/log/secure # CentOS
Quick Reference
Common Error Codes
- Exit 255: Generic error
- Exit 1: Invalid command
- Exit 126: Command not executable
- Exit 127: Command not found
Essential SSH Commands
ssh-keygen # Generate new key
ssh-copy-id # Copy key to server
ssh-add # Add key to agent
ssh-keyscan # Scan host keys
Next Steps
After mastering SSH troubleshooting:
- Set up SSH config files
- Implement key rotation
- Configure bastion hosts
- Explore modern alternatives
For a hassle-free experience without SSH complexity, check out Thunder Compute where you can access your instances directly through your browser!
Subscribe via RSS