If you're experiencing SSH issues on your VPS, follow these basic troubleshooting steps to identify and resolve the problem.
Incorrect VPS Password
If you cannot connect to your VPS because of an incorrect or forgotten password, you can reset your VPS root password via the client area. Follow the provided guide for detailed instructions.
Unresponsive SSH Connection
If your SSH connection attempts are timing out or being immediately rejected, the SSH service might not be running, or the firewall might be blocking SSH connections. You can connect to your VPS via the Emergency Console to investigate further.
Checking SSH Status
To check the status of the SSH service, connect to your VPS and run one of the following commands:
1.Ubuntu 16.04+, Debian 8+, CentOS 7+:
sudo systemctl status sshd -l
2.CentOS 6:
sudo service sshd status
3.Ubuntu 14.04, Debian 7:
sudo service ssh status
Restarting SSH Service
If the SSH service is not running, restart it using the following commands:
1.Ubuntu 16.04+, Debian 8+, CentOS 7+:
sudo systemctl restart sshd
2.CentOS 6:
sudo service sshd restart
3.Ubuntu 14.04, Debian 7:
sudo service ssh restart
Checking SSH Logs
If restarting the service doesn't help, check the SSH logs for more information:
1.Ubuntu 16.04+, Debian 8+, CentOS 7+:
sudo journalctl -u sshd -u ssh
2.CentOS 6:
less /var/log/secure
3.Ubuntu 14.04, Debian 7:
less /var/log/auth.log
SSH Running on a Non-Standard Port
If SSH is active, verify the port it's running on by using the netstat
command:
sudo netstat -plntu | grep ssh
By default, SSH runs on port 22. If a different port is in use, connect using that port:
ssh username@IP_address -p port
Port Conflict with Another Service
If another service is using the same port as SSH, you will see an error like:
Bind to port 22 on 0.0.0.0 failed: Address already in use.
Resolve this by:
1.Binding SSH to a Different Port:
Follow the guide to change the SSH port.
2.Stopping the Other Service:
2.1 Identify the service using the same port:
sudo netstat -plntu | grep :22
2.1 Stop and disable the conflicting service:
sudo systemctl stop some-other-service
sudo systemctl disable some-other-service
3.Changing the Other Service's Port:
Adjust the configuration of the conflicting service to use a different port and restart SSH.
Misconfigured Firewall Rules for SSH
If SSH service starts but connections still fail, review your firewall rules:
1.Display IPv4 rules:
sudo iptables-save
2.Display IPv6 rules:
sudo ip6tables-save
For UFW or FirewallD, check the status:
1.UFW:
sudo ufw status
2.FirewallD:
sudo firewall-cmd --state
Ensure the SSH rule is correct:
-A INPUT -p tcp -m tcp --dport 22 -m conntrack --ctstate NEW -j ACCEPT
Disabling Firewall Rules Temporarily
To rule out firewall issues, temporarily disable the firewall (not recommended for long periods due to security risks):
1.Backup current firewall rules:
sudo iptables-save > ~/iptables.txt
2.Set default policies to ACCEPT:
sudo iptables -P INPUT ACCEPT
sudo iptables -P FORWARD ACCEPT
sudo iptables -P OUTPUT ACCEPT
3.Flush tables:
sudo iptables -t nat -F
sudo iptables -t mangle -F
sudo iptables -F
sudo iptables -X
Repeat these steps with ip6tables for IPv6 rules.
Rejected SSH Logins
If SSH is running but login attempts are rejected, check the logs for rejected attempts and ensure root logins are not disabled:
grep PermitRootLogin /etc/ssh/sshd_config
If PermitRootLogin
is set to no
, either log in with another user or change it to yes and restart SSH.
By following these steps, you can effectively troubleshoot and resolve common SSH issues on your VPS.