Troubleshooting SSH Connection Refused Errors is a common requirement for VPS administrators. This guide provides practical instructions that you can follow on Ubuntu 22.04/24.04 or Debian 12, though most steps apply to other distributions as well.
Prerequisites
- Root or sudo access to the server
- Basic knowledge of Linux system administration
- SSH access to the affected server
- Basic familiarity with the Linux command line
- A VPS running Ubuntu 22.04 or later (2GB+ RAM recommended)
Identifying the Problem
Security should be a primary consideration when configuring ssh. Always use strong passwords, keep software updated, and restrict network access to only the necessary ports and IP addresses.
# Diagnostic commands for ssh issues
sudo dmesg | tail -50 # Kernel messages
sudo journalctl -xe # Recent system errors
sudo systemctl status ssh # Service status
# Check resource usage
top -bn1 | head -20
free -h
df -ih # inode usage
The configuration above sets the recommended values for a VPS with 2-4GB of RAM. Adjust the memory-related settings proportionally if your server has different specifications.
Diagnostic Commands
If you encounter issues during setup, check the system logs first. Most problems can be diagnosed by examining the output of journalctl or the application-specific log files in /var/log/.
# Network troubleshooting
ping -c 4 8.8.8.8 # Basic connectivity
traceroute example.com # Route tracing
mtr --report example.com # Combined ping+traceroute
ss -tlnp # Listening ports
curl -I https://example.com # HTTP response headers
These commands should be run as root or with sudo privileges. If you're using a non-root user, prefix each command with sudo.
- Maintain runbooks for common operations
- Document all configuration changes
- Set up monitoring before going to production
Wrapping Up
Following this guide, your ssh setup should be production-ready. Keep an eye on resource usage as your traffic grows and don't forget to test your backup and recovery procedures periodically.