If you’ve attempted to establish an SSH connection to a remote server and received a “Connection Timed Out” error message, don’t worry! This is a common issue…
Here’s a step-by-step guide for easily fixing the SSH Connection Timed Out error. 😃
By the way, What does SSH "connection timed out" mean?
This error happens when the computer tries to connect with a server through SSH and it waits for a response on the other end. If, in a certain amount of time, SSH doesn't connect, it says, "Connection Timed Out." That really only tells you that your computer couldn't communicate with the server, but it's not sure exactly why.
Solutions
Check if the Server is Running
Make sure the server is up and running. You can verify this by pinging the server or by contacting the server administrator for its status.
To ping the server, use the following command: replace the IP of your server with the IP of your machine.
ping <ip_address>
If you get a response like “Request Timed Out” or “Destination Host Unreachable,” the server might be down.
Verify the SSH Port
SSH uses port 22 by default, but the server might use a different port. If your server uses a custom port, you’ll need to specify it in the command. You can use the SSH connecting command like the below:
ssh -p 2222 [email protected]
Remember to replace the username, server IP address, and SSH port with the correct values as of your server.
Check Firewall Settings (on Your PC and the Server)
If a firewall is blocking your SSH connection, you must adjust its settings.
On your local machine, make sure the firewall allows outgoing SSH connections on port 22, or whichever custom port is utilized.
On your server side, check whether SSH connections are allowed if you have access to the server by any means.
sudo ufw allow ssh
Or, if SSH runs on a different port:
sudo ufw allow <port number>
If you’re not using the UFW firewall, adjust these settings by referring to the blog: https://www.veeble.org/kb/how-to-open-a-specific-port-on-linux/
Self-Assessment of Your End Issues
- Open up any other site on your browser to make sure you are online and the Internet is working without issues.
- Check the Internet speed also via visiting the speed testing websites available in your search engine, such as SpeedTest by Ookla.
- Double-check the IP address of the server and make sure you’re using the correct one.
Increase Connection Timeout
You can increase the SSH timeout value to give the server more time to respond. Sometimes the server might be slow to respond, and the default timeout period might be too short. So to alter it and connect to the server, use the following command format:
ssh -o ConnectTimeout=30 user@server_ip_address
In this example, 30
represents the number of seconds before timing out.
Check Server Logs for Errors
If you have access to the server logs, check them for any signs of SSH-related issues. You can usually find the logs in /var/log/auth.log or /var/log/secure, depending on your system.
cat /var/log/auth.log
OR
cat /var/log/secure
Advanced Troubleshooting (Optional)
If you are still facing issues connecting to SSH, it is recommended to check any blocks for your IP in your server’s firewall as well as the below blog SSH access regaining solutions:
The “Connection Timed Out” error in SSH can be frustrating, but with this guide, you can troubleshoot and fix the issue easily. Most of the time, the problem is with either a firewall, the wrong SSH port, or a network connection. By following these simple steps, you’ll be able to connect to your server in no time!