
Secure Shell (SSH) is a commonly used protocol that provides secure command-line access to your Linux systems. However, at times, you may encounter the “SSH Connection Refused” error, which can be quite frustrating. This article will guide you through the steps to fix this issue on a local network.
To fix the "SSH Connection Refused" error on a local network, you need to check if the SSH server is installed and running on the target host, verify that the SSH port (default is 22) is open and accessible, ensure that the target host is on the same local network as the connecting host, and check for any specific SSH configuration settings that may be causing the issue.
Checking if SSH Server is Installed
The first step in troubleshooting the SSH connection refused error is to ensure that the SSH server is installed on the target host. You can verify this by using the following command:
dpkg -l openssh-server
The dpkg -l
command lists all the installed packages on your system. If the SSH server is not installed, you can install it using the following commands:
sudo apt update
sudo apt install -y ssh
The sudo apt update
command updates the list of available packages, and the sudo apt install -y ssh
command installs the SSH server.
Verifying the SSH Service
Next, make sure that the SSH service is running on the target host. You can restart the SSH service using the following command:
sudo service ssh restart
If you encounter the error “sshd: unrecognized service”, it may indicate that the SSH service is not installed or named differently. In that case, try using the following command:
sudo systemctl restart ssh
Checking the SSH Port
By default, SSH uses port 22. Therefore, you need to ensure that this port is open and accessible on the target host. Use the following command to check if the port is in use:
netstat -atn | grep :22
The netstat -atn
command displays all network connections, and the grep :22
part filters the output to show only connections on port 22. If port 22 is not in use, you may need to configure your firewall to allow incoming connections on port 22.
Verifying the Network Configuration
Ensure that the target host is on the same local network as the connecting host. Verify the IP address of the target host using the following command:
ifconfig
or
ip addr show
These commands display the network configuration of your system. Make sure the IP address matches the one you are trying to connect to.
Checking SSH Configuration Settings
Finally, check if there are any specific SSH configuration settings that may be causing the issue. Open the SSH server configuration file using the following command:
sudo vim /etc/ssh/sshd_config
In this file, make sure the “PermitRootLogin” setting is set to “yes” if you are trying to connect as the root user. If it’s set to “no”, change it to “yes” and save the file.
Conclusion
Troubleshooting SSH connection issues can be a bit challenging, especially if you’re new to Linux. However, by following the steps outlined in this article, you should be able to resolve the “SSH Connection Refused” error on your local network. If none of the above solutions work, you may need to provide more information about your setup, such as the specific command you are using to connect, the Ubuntu version, and any firewall or network configurations that may be relevant.
Remember, the key to successful troubleshooting is patience and a methodical approach. Good luck!
The "SSH Connection Refused" error typically occurs when the SSH server on the target host is not accepting incoming connections. This can be due to various reasons, such as the SSH server not being installed or running, the SSH port being blocked, or incorrect network configurations.
You can check if the SSH server is installed by running the command dpkg -l openssh-server
. This command will list all the installed packages on your system, and if the SSH server is installed, it will be listed as "openssh-server".
To install the SSH server, you can use the following commands:
sudo apt update
sudo apt install -y ssh
The first command updates the list of available packages, and the second command installs the SSH server.
You can restart the SSH service using the command sudo service ssh restart
. If you encounter the error "sshd: unrecognized service", it may indicate that the SSH service is not installed or named differently. In that case, try using the command sudo systemctl restart ssh
.
To check if the SSH port (default is port 22) is in use, you can run the command netstat -atn | grep :22
. This command will display all network connections, and the grep :22
part filters the output to show only connections on port 22. If port 22 is not in use, you may need to configure your firewall to allow incoming connections on port 22.
You can verify the network configuration of the target host by running the command ifconfig
or ip addr show
. These commands will display the network configuration of your system, including the IP address. Make sure the IP address matches the one you are trying to connect to.
Yes, there may be specific SSH configuration settings that can cause the error. To check the SSH server configuration, you can open the SSH server configuration file using the command sudo vim /etc/ssh/sshd_config
. In this file, make sure the "PermitRootLogin" setting is set to "yes" if you are trying to connect as the root user. If it’s set to "no", change it to "yes" and save the file.
If none of the above solutions work, it may be necessary to provide more information about your setup, such as the specific command you are using to connect, the Ubuntu version, and any firewall or network configurations that may be relevant. This will help in further troubleshooting the issue.