How Do You Troubleshoot “ssh connect to host x.x.x.x port 22: Connection refused”?

Problem scenario
You get “ssh connect to host x.x.x.x port 22: Connection refused” when trying to SSH. What do you do?

Possible solution #1
Do you have the correct IP address? Can you copy and paste the IP address? Can you run "ip addr show" on different servers? Is the IP addressed used multiple times in different subnets? It could refer to different servers. Human error could contribute to this error.

Possible solution #2
Has openssh-server been installed? If you have a Debian or Ubuntu distribution of Linux, run this command: sudo apt -y install openssh-server

Possible solution #3
Is the sshd service running? Try sudo systemctl start sshd

Possible solution #4
Is port 22 blocked via a firewall, IDS, IPS, or router?

Possible solution #5
This only applies when you are trying to remote into your Mac system from another Linux server. On the Mac open System Preferences. Go to “Sharing”. Go to “Remote Login” and check it if it is unchecked. Now you can go back to the Linux system and try again.

Leave a comment

Your email address will not be published. Required fields are marked *