How to Setup WireGuard VPN on VPS | Ubuntu Gu...
In a world valuing online privacy, Virtual Private Netw...
SSH, also known as Secure Shell, is a protocol used to access computers securely over a network, Since it encrypts the data sent over the network, it is especially useful in public or unsecured networks.
You probably remember the annoyance of seeing the “SSH Connection Refused” error message when trying to connect with a Linux remote server. This is especially true for administrators whose job revolves around managing remote servers. SSH is essential for any remote server’s secure management and access, but this error indicates the inability to access the SSH service on the server side which blocks all connection attempts. In this article, we explore the key reasons behind this issue and offer practical solutions to resolve SSH connection problems.
A few frequent reasons your SSH link gets refused are listed below:
You can follow the below steps to troubleshoot SSH connection refused error.
Step 1: Incorrect Credentials
People often lose track of their usernames, especially when they juggle several accounts or havent signed in for months. If that happens, and the server permits it, you can look for the name by sifting through old emails, user manuals, or simply asking the system admin for help.
Should you forget your password, a reset is usually straightforward; you answer security questions or grab a new link sent to your inbox. If those options fail, reach out to IT support. They can change the password directly or walk you through whatever next step is needed.
Step 2: Verify SSH Service Status
To start troubleshooting the SSH error connection refused, the first step is to confirm whether the SSH service is running on both the client and server sides. This can be done by checking the service status using the appropriate command.
On the server side, execute the below command to check the status of the SSH service.
sudo systemctl status ssh
This command provides information about whether the service is active, inactive, or encountering any errors.
Similarly, on the client side, use commands like `service ssh status` or `systemctl status sshd` to verify the status of the SSH service.
sudo systemctl status ssh
Executing either of these commands on the client side will provide information about the status of the SSH service running locally. This information helps to ensure that SSH service is running and available for making connections.
Step 3: Check SSH Port Configuration
If the SSH service is running but you’re still encountering the Connection Refused Error, it’s crucial to ensure that the SSH service is configured to listen on the correct port. Here’s how you can do it:
On the server side, you can open the SSH server configuration file using the nano or vi text editor:
nano /etc/ssh/sshd_config
By default, SSH operates on port 22. Ensure that the Port directive specifies the correct port number.
Similarly, on the client side, you can open the SSH client configuration file, usually located at /etc/ssh/ssh_config
. Again, you can use a text editor like nano or vi.
nano /etc/ssh/ssh_config
Though it typically lacks a port specification, verify your connection port. After inspecting both files, ensure port consistency and save changes to resolve the issue.
Unlock the power of Ulta SSH VPS
Buy SSH Full Linux Root Virtual Private Servers with Instant Setup, Our VPS includes a free trial for 30 days, Choose different Linux-based operating systems.
Step 4: Review Firewall Settings
Firewalls, both on the server and within the network infrastructure, can sometimes block SSH connections. To ensure proper SSH connectivity, it’s essential to review and potentially adjust firewall settings.
You can use the iptables command to review the firewall settings on the server where the SSH service is running:
sudo iptables -L
Ensure that there are rules typically port 22 allowing incoming connections on the SSH port.
Similarly, if you identify that SSH traffic is being blocked by the server’s firewall, you can add a rule to allow SSH connections. For example, using iptables, you can add a rule to allow incoming SSH traffic on port 22 with the following command:
sudo iptables -A INPUT -p tcp --dport 22 -j ACCEPT
If SSH traffic is being blocked by a network firewall, you’ll need to adjust its settings to allow SSH connections. This typically involves accessing the firewall’s configuration interface and adding a rule or policy to permit SSH traffic on port 22.
After adjusting the firewall settings, remember to save the changes to ensure they persist across reboots or configuration changes.
Step 5: Whitelist IP Addresses
If the server is configured to only allow SSH connections from specific IP addresses, it’s essential to ensure that your IP address is whitelisted.
This information can usually be found in the SSH server configuration file which can be accessed using:
nano /etc/ssh/sshd_config
Look for directives such as AllowUsers, AllowGroups, or DenyUsers that specify which users or IP addresses are allowed or denied SSH access.
Once your IP address has been whitelisted, it’s important to ensure that it’s correctly configured in the SSH server’s configuration file. For this, you can open the SSH server configuration file (sshd_config) on the server side using a text editor:
nano /etc/ssh/sshd_config
After making the necessary changes, save the file and restart the SSH service to apply the new configuration.
sudo systemctl restart sshd
Step 6: Network Connectivity Checks
Finally, verify the network connectivity between the client and server that you can do by executing the following command:
ping <server_ip_or_hostname>
The ping command can be used to check for network connectivity between the client and server. The ping command sends ICMP echo requests to the target server and waits for responses.
Replace with the IP address or hostname of the server you’re trying to connect to. Running this command will indicate whether there’s network connectivity between the client and server. A successful ping indicates that the network is reachable.
SSH (Secure Shell) has become the go-to tool for managing servers safely from a distance. When a connection is refused, the cause might be a stopped SSH service, a wrong port number, rigid firewall rules, or an IP address that has not been cleared to connect.
Working through each possibility one by one lets users clear the error and restore smooth, secure remote access.
Encountering an “SSH Connection Refused” error on your server can be a roadblock to remote access. Upgrading to an Ultahost Linux VPS server empowers you to diagnose and fix the issue effectively which grants you root access and full control over your server configuration. This allows you to verify if SSH is running, adjust firewall settings, or even reinstall SSH if necessary.
The “SSH Connection Refused” error indicates that the SSH server rejected the connection attempt. This can happen due to various reasons, such as incorrect configuration, firewall settings, or SSH service not running.
Start by ensuring that the SSH service is running on the server you’re trying to connect to. Check firewall settings to ensure SSH traffic is allowed. Verify the SSH configuration file (/etc/ssh/sshd_config
on most Linux systems) for any misconfigurations.
You can check if the SSH service is running on the server by using the systemctl status ssh
command on Linux systems. This command will display the status of the SSH service and whether it’s running or not.
You can start the SSH service using the appropriate command for your operating system. For example, on many Linux distributions, you can start the SSH service with sudo systemctl start sshd
.
You can use the telnet command to check if the SSH port (default is 22) is open on the server. For example, telnet server_ip 22
. If the connection is successful, the port is open; otherwise, it’s closed or blocked.