{"id":3937,"date":"2024-06-11T22:12:53","date_gmt":"2024-06-11T16:42:53","guid":{"rendered":"https:\/\/www.veeble.org\/kb\/?p=3937"},"modified":"2025-04-09T12:05:08","modified_gmt":"2025-04-09T06:35:08","slug":"troubleshooting-ssh-connection-refused-error","status":"publish","type":"post","link":"https:\/\/www.veeble.com\/kb\/troubleshooting-ssh-connection-refused-error\/","title":{"rendered":"Troubleshooting &#8220;SSH Connection Refused&#8221; Error and Regaining Access"},"content":{"rendered":"\n<figure class=\"wp-block-gallery has-nested-images columns-default is-cropped wp-block-gallery-1 is-layout-flex wp-block-gallery-is-layout-flex\">\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/www.veeble.org\/kb\/wp-content\/uploads\/2024\/06\/Linux-Symbol.jpg\" target=\"_blank\" rel=\"noopener\"><img fetchpriority=\"high\" decoding=\"async\" width=\"1080\" height=\"397\" data-id=\"3982\" src=\"https:\/\/www.veeble.org\/kb\/wp-content\/uploads\/2024\/06\/Linux-Symbol.jpg\" alt=\"Troubleshooting &quot;SSH Connection Refused&quot; Error and Regaining Access\" class=\"wp-image-3982\" srcset=\"https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2024\/06\/Linux-Symbol.jpg 1080w, https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2024\/06\/Linux-Symbol-300x110.jpg 300w, https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2024\/06\/Linux-Symbol-1024x376.jpg 1024w, https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2024\/06\/Linux-Symbol-768x282.jpg 768w\" sizes=\"(max-width: 1080px) 100vw, 1080px\" \/><\/a><\/figure>\n<\/figure>\n\n\n\n<p>Are you facing the dreaded &#8220;SSH Connection Refused&#8221; error while trying to access your server? Don&#8217;t panic! In this comprehensive step-by-step guide, we will help you troubleshoot the issue and regain access to your SSH connection. In this article, we will walk you through the troubleshooting process, providing easy-to-follow instructions that will help you pinpoint the root cause of the error. From checking your network settings to verifying SSH server configuration, we will cover every possible reason behind the connection refused error.<\/p>\n\n\n\t\t\t\t<div class=\"wp-block-uagb-table-of-contents uagb-toc__align-left uagb-toc__columns-1  uagb-block-e7ad8ccf      \"\n\t\t\t\t\tdata-scroll= \"1\"\n\t\t\t\t\tdata-offset= \"30\"\n\t\t\t\t\tstyle=\"\"\n\t\t\t\t>\n\t\t\t\t<div class=\"uagb-toc__wrap\">\n\t\t\t\t\t\t<div class=\"uagb-toc__title\">\n\t\t\t\t\t\t\tTable Of Contents\t\t\t\t\t\t<\/div>\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<div class=\"uagb-toc__list-wrap \">\n\t\t\t\t\t\t<ol class=\"uagb-toc__list\"><li class=\"uagb-toc__list\"><a href=\"#checking-ssh-credentials\" class=\"uagb-toc-link__trigger\">Checking SSH Credentials<\/a><li class=\"uagb-toc__list\"><a href=\"#checking-network-connectivity\" class=\"uagb-toc-link__trigger\">Checking Network Connectivity<\/a><li class=\"uagb-toc__list\"><a href=\"#verifying-ssh-server-status\" class=\"uagb-toc-link__trigger\">Verifying SSH Server Status<\/a><li class=\"uagb-toc__list\"><a href=\"#verifying-ssh-server-configuration\" class=\"uagb-toc-link__trigger\">Verifying SSH Server Configuration<\/a><li class=\"uagb-toc__list\"><a href=\"#dealing-with-firewall-and-port-blocking-issues\" class=\"uagb-toc-link__trigger\">Dealing with Firewall and Port-Blocking Issues<\/a><li class=\"uagb-toc__list\"><a href=\"#checking-ssh-logs\" class=\"uagb-toc-link__trigger\">Checking SSH Logs<\/a><li class=\"uagb-toc__list\"><a href=\"#troubleshooting-ssh-client-configuration\" class=\"uagb-toc-link__trigger\">Troubleshooting SSH client configuration<\/a><li class=\"uagb-toc__list\"><a href=\"#reinstalling-ssh-service-and-restarting-the-server\" class=\"uagb-toc-link__trigger\">Reinstalling SSH Service and Restarting the Server<\/a><\/ol>\t\t\t\t\t<\/div>\n\t\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\n\n\n<p><\/p>\n\n\n\n<p>This common issue can arise due to various reasons, such as SSH authentic failures, network problems, server misconfigurations, or firewall restrictions. Identifying the root cause is crucial to restoring your SSH access. By understanding the typical triggers behind this error, you can streamline the troubleshooting process and expedite the resolution.<\/p>\n\n\n\n<p><\/p>\n\n\n<h4 class=\"wp-block-heading\" id=\"checking-ssh-credentials\">Checking SSH Credentials<\/h4>\n\n\n<p>The foremost solution is to check the user credentials you tried to connect via SSH into the server were correct. This includes IP address, username, password, and the SSH port. A typo in any of these fields can lead to the server refusing your connection. By double-checking your credentials, you can rule out a simple mistake as the cause of the connection failure. If the credentials are correct, then go ahead with the next steps for resolving the issue.<\/p>\n\n\n\n<p><\/p>\n\n\n<h4 class=\"wp-block-heading\" id=\"checking-network-connectivity\">Checking Network Connectivity<\/h4>\n\n\n<p>One of the primary culprits for the SSH connection refused error is incorrect network settings. Ensure that your server is connected to the internet and that no network disruptions are causing the communication breakdown.  To check that you can use the <a href=\"https:\/\/linux.die.net\/man\/8\/ping\" target=\"_blank\" rel=\"noopener\">Ping tool<\/a> to ping the server first:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ping <em>&lt;server ip&gt;<\/em><\/code><\/pre>\n\n\n\n<p>Replace the <em>&lt;server ip&gt;<\/em> with the server IP of your SSH connection issue machine.<\/p>\n\n\n\n<figure class=\"wp-block-gallery has-nested-images columns-default is-cropped wp-block-gallery-2 is-layout-flex wp-block-gallery-is-layout-flex\">\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/www.veeble.org\/kb\/wp-content\/uploads\/2024\/06\/Screenshot-2024-06-11-193218.png\" target=\"_blank\" rel=\"noopener\"><img decoding=\"async\" width=\"875\" height=\"76\" data-id=\"3954\" src=\"https:\/\/www.veeble.org\/kb\/wp-content\/uploads\/2024\/06\/Screenshot-2024-06-11-193218.png\" alt=\"ping reachable\" class=\"wp-image-3954\" srcset=\"https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2024\/06\/Screenshot-2024-06-11-193218.png 875w, https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2024\/06\/Screenshot-2024-06-11-193218-300x26.png 300w, https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2024\/06\/Screenshot-2024-06-11-193218-768x67.png 768w\" sizes=\"(max-width: 875px) 100vw, 875px\" \/><\/a><\/figure>\n<\/figure>\n\n\n\n<p>If you are getting ping like the above picture, it means there are no issues with network connectivity. You can go ahead with the next steps. If the ping to the server IP does not function as expected as in below screenshot, it indicates that the issue lies not with SSH, but with network connectivity, which is beyond the scope of this blog.<\/p>\n\n\n\n<figure class=\"wp-block-gallery has-nested-images columns-default is-cropped wp-block-gallery-3 is-layout-flex wp-block-gallery-is-layout-flex\">\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/www.veeble.org\/kb\/wp-content\/uploads\/2024\/06\/Screenshot-2024-06-11-193231.png\" target=\"_blank\" rel=\"noopener\"><img decoding=\"async\" width=\"857\" height=\"80\" data-id=\"3955\" src=\"https:\/\/www.veeble.org\/kb\/wp-content\/uploads\/2024\/06\/Screenshot-2024-06-11-193231.png\" alt=\"ping unreachable\" class=\"wp-image-3955\" srcset=\"https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2024\/06\/Screenshot-2024-06-11-193231.png 857w, https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2024\/06\/Screenshot-2024-06-11-193231-300x28.png 300w, https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2024\/06\/Screenshot-2024-06-11-193231-768x72.png 768w\" sizes=\"(max-width: 857px) 100vw, 857px\" \/><\/a><\/figure>\n<\/figure>\n\n\n\n<p>The next step is to check the connectivity via a specific SSH port to the server. This can be checked with the Telnet tool. For Windows users, you can visit the website <a href=\"https:\/\/portchecker.co\/\" target=\"_blank\" rel=\"noopener\">https:\/\/portchecker.co\/<\/a> to check if the port is open for connections.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>tel<span style=\"color: var(--ast-global-color-3)\">net<\/span><span style=\"color: var(--ast-global-color-3)\"> &lt;hostname_or_IP_address&gt;<\/span><span style=\"background-color: initial;color: var(--ast-global-color-3)\"> &lt;port&gt; <\/span><\/code><\/pre>\n\n\n\n<p>Replace <code>&lt;hostname_or_IP_address&gt;<\/code> with the hostname or IP address of the server and <code>&lt;port&gt;<\/code> with the SSH port you are using for SSH.<\/p>\n\n\n\n<p>If the port is open and the SSH service is running, you will see a response similar to this:<\/p>\n\n\n\n<figure class=\"wp-block-gallery has-nested-images columns-default is-cropped wp-block-gallery-4 is-layout-flex wp-block-gallery-is-layout-flex\">\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/www.veeble.org\/kb\/wp-content\/uploads\/2024\/06\/Screenshot-2024-06-11-192153.png\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" width=\"858\" height=\"119\" data-id=\"3951\" src=\"https:\/\/www.veeble.org\/kb\/wp-content\/uploads\/2024\/06\/Screenshot-2024-06-11-192153.png\" alt=\"telnet connected screen\" class=\"wp-image-3951\" srcset=\"https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2024\/06\/Screenshot-2024-06-11-192153.png 858w, https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2024\/06\/Screenshot-2024-06-11-192153-300x42.png 300w, https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2024\/06\/Screenshot-2024-06-11-192153-768x107.png 768w\" sizes=\"(max-width: 858px) 100vw, 858px\" \/><\/a><\/figure>\n<\/figure>\n\n\n\n<p>If the port is closed or blocked by any firewall rules or misconfiguration inside the server, you will see a response indicating that the connection refused:<\/p>\n\n\n\n<figure class=\"wp-block-gallery has-nested-images columns-default is-cropped wp-block-gallery-5 is-layout-flex wp-block-gallery-is-layout-flex\">\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/www.veeble.org\/kb\/wp-content\/uploads\/2024\/06\/Screenshot-2024-06-11-192226.png\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" width=\"877\" height=\"89\" data-id=\"3952\" src=\"https:\/\/www.veeble.org\/kb\/wp-content\/uploads\/2024\/06\/Screenshot-2024-06-11-192226.png\" alt=\"telnet connection refused for port 22\" class=\"wp-image-3952\" srcset=\"https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2024\/06\/Screenshot-2024-06-11-192226.png 877w, https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2024\/06\/Screenshot-2024-06-11-192226-300x30.png 300w, https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2024\/06\/Screenshot-2024-06-11-192226-768x78.png 768w\" sizes=\"(max-width: 877px) 100vw, 877px\" \/><\/a><\/figure>\n<\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p class=\"has-vivid-red-color has-text-color has-link-color wp-elements-c031b4827ff5ab2e8176e140cc9a411c\">To proceed further, you must have access to the server through alternative methods such as physical access, VNC console, IPMI access, or any other means. Without such access, it will not be possible to check or resolve the issue with SSH.<\/p>\n\n\n\n<p><\/p>\n\n\n<h4 class=\"wp-block-heading\" id=\"verifying-ssh-server-status\">Verifying SSH Server Status<\/h4>\n\n\n<p>After reviewing the network connectivity via ping the next step is to check if the SSH service is running on the server. Verifying this fundamental aspect is crucial for an issue related to SSH service.<\/p>\n\n\n\n<p>To check if the SSH service is running, access the server via any other methods such as console and execute the following command:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo systemctl status ssh<\/code><\/pre>\n\n\n\n<p>This command will show the status of the SSH service. If it is running, you will see &#8220;active (running)&#8221; like the below screenshot.<\/p>\n\n\n\n<figure class=\"wp-block-gallery has-nested-images columns-default is-cropped wp-block-gallery-6 is-layout-flex wp-block-gallery-is-layout-flex\">\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/www.veeble.org\/kb\/wp-content\/uploads\/2024\/06\/Screenshot-2024-06-11-195355.png\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" width=\"1002\" height=\"359\" data-id=\"3958\" src=\"https:\/\/www.veeble.org\/kb\/wp-content\/uploads\/2024\/06\/Screenshot-2024-06-11-195355.png\" alt=\"check ssh service status with the help of sudo systemctl status ssh\" class=\"wp-image-3958\" srcset=\"https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2024\/06\/Screenshot-2024-06-11-195355.png 1002w, https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2024\/06\/Screenshot-2024-06-11-195355-300x107.png 300w, https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2024\/06\/Screenshot-2024-06-11-195355-768x275.png 768w\" sizes=\"(max-width: 1002px) 100vw, 1002px\" \/><\/a><\/figure>\n<\/figure>\n\n\n\n<p>On some systems, the service might be named <code>sshd<\/code> instead of <code>ssh<\/code>. If the above command doesn&#8217;t work for you use: <code>sudo systemctl status sshd<\/code> instead. <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><code>sudo systemctl status sshd<\/code><\/code><\/pre>\n\n\n\n<p>If it is not working, you will see either an inactive status or a disabled status. You can need to enable and activate it by the following commands:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo systemctl enable ssh\nsudo systemctl restart ssh<\/code><\/pre>\n\n\n\n<p>If you encounter any errors while executing commands related to SSH or if you still find the SSH service inactive after executing the above commands, you should check the system logs using <code>journalctl<\/code> for more information about the issue.<br>You can view the logs related to SSH via the following command:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo journalctl -u ssh<\/code><\/pre>\n\n\n\n<p class=\"has-text-align-center\">OR<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo journalctl -u sshd<\/code><\/pre>\n\n\n\n<p>This command will display log messages related to the SSH service, including any errors or warnings that may help diagnose the issue.<\/p>\n\n\n\n<p><\/p>\n\n\n<h4 class=\"wp-block-heading\" id=\"verifying-ssh-server-configuration\">Verifying SSH Server Configuration<\/h4>\n\n\n<p>A critical aspect of troubleshooting the SSH connection refused error is examining the server-side configuration settings. Start by reviewing the SSH server&#8217;s configuration file, typically at \/etc\/ssh\/sshd_config. Check parameters related to authentication, access controls, and port settings.<\/p>\n\n\n\n<p>Inspect the SSH server&#8217;s access control rules. Ensure the AllowUsers and AllowGroups directives include the appropriate user accounts and groups for SSH access. Validate the SSH server&#8217;s port configuration. SSH typically operates on port 22, but confirm this in the configuration file. If running on a non-standard port, ensure your SSH client connects to the correct port. These adjustments can often resolve connectivity issues and mitigate the SSH connection refused error.<\/p>\n\n\n\n<p>Open the SSH server configuration file with a text editor (e.g., nano, vi, or vim) and verify the values you have configured, such as the port number, PermitRootLogin, and PasswordAuthentication. Adjust these settings as needed to ensure they meet your requirements:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo nano \/etc\/ssh\/sshd_config<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-gallery has-nested-images columns-default is-cropped wp-block-gallery-7 is-layout-flex wp-block-gallery-is-layout-flex\">\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/www.veeble.org\/kb\/wp-content\/uploads\/2024\/06\/Screenshot-2024-06-11-205539-1.png\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" width=\"1076\" height=\"1023\" data-id=\"3970\" src=\"https:\/\/www.veeble.org\/kb\/wp-content\/uploads\/2024\/06\/Screenshot-2024-06-11-205539-1.png\" alt=\"sudo nano \/etc\/ssh\/sshd_config\" class=\"wp-image-3970\" srcset=\"https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2024\/06\/Screenshot-2024-06-11-205539-1.png 1076w, https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2024\/06\/Screenshot-2024-06-11-205539-1-300x285.png 300w, https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2024\/06\/Screenshot-2024-06-11-205539-1-1024x974.png 1024w, https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2024\/06\/Screenshot-2024-06-11-205539-1-768x730.png 768w\" sizes=\"(max-width: 1076px) 100vw, 1076px\" \/><\/a><\/figure>\n<\/figure>\n\n\n\n<p>After verifying and editing the configuration, restart the SSH service with command:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo systemctl restart ssh<\/code><\/pre>\n\n\n\n<p class=\"has-text-align-center\">OR<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo systemctl restart sshd<\/code><\/pre>\n\n\n\n<p><\/p>\n\n\n<h4 class=\"wp-block-heading\" id=\"dealing-with-firewall-and-portblocking-issues\">Dealing with Firewall and Port-Blocking Issues<\/h4>\n\n\n<p>Firewall restrictions and port blocking issues are common culprits behind the SSH connection refused error, particularly in environments with stringent security policies. Firewalls, both at the server and network levels, can filter incoming connections and block traffic on specific ports, including the default SSH port 22. Resolving firewall and port-blocking issues involves adjusting the firewall rules to permit SSH traffic and unblocking the necessary ports.<\/p>\n\n\n\n<p>For this, at first place, you need to check if the SSH daemon is running and listening on the designated port (usually port 22) via system monitoring tools like <code>netstat<\/code> or <code>ss<\/code> . Inorder to check it use one of the tool from it:<\/p>\n\n\n\n<p><strong>Using Netstat tool:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>netstat -tuln | grep :22<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-gallery has-nested-images columns-default is-cropped wp-block-gallery-8 is-layout-flex wp-block-gallery-is-layout-flex\">\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/www.veeble.org\/kb\/wp-content\/uploads\/2024\/05\/Screenshot-2024-05-30-220401.png\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" width=\"862\" height=\"165\" data-id=\"3549\" src=\"https:\/\/www.veeble.org\/kb\/wp-content\/uploads\/2024\/05\/Screenshot-2024-05-30-220401.png\" alt=\"netstat open ports\" class=\"wp-image-3549\" srcset=\"https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2024\/05\/Screenshot-2024-05-30-220401.png 862w, https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2024\/05\/Screenshot-2024-05-30-220401-300x57.png 300w, https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2024\/05\/Screenshot-2024-05-30-220401-768x147.png 768w\" sizes=\"(max-width: 862px) 100vw, 862px\" \/><\/a><\/figure>\n<\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p><strong>Using SS tool:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ss -tuln | grep :22<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/www.veeble.org\/kb\/wp-content\/uploads\/2024\/05\/Screenshot-2024-05-30-221304.png\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" width=\"881\" height=\"146\" src=\"https:\/\/www.veeble.org\/kb\/wp-content\/uploads\/2024\/05\/Screenshot-2024-05-30-221304.png\" alt=\"Open ports ss tool\" class=\"wp-image-3552\" srcset=\"https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2024\/05\/Screenshot-2024-05-30-221304.png 881w, https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2024\/05\/Screenshot-2024-05-30-221304-300x50.png 300w, https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2024\/05\/Screenshot-2024-05-30-221304-768x127.png 768w\" sizes=\"(max-width: 881px) 100vw, 881px\" \/><\/a><\/figure>\n\n\n\n<p>If there is any output for these commands showing <strong>:22 <\/strong>or the SSH port of yours in it, then they are listening and open. If not, then try opening the ports via your firewall.<\/p>\n\n\n\n<p>Use the appropriate command for your operating system&#8217;s firewalls:<\/p>\n\n\n<h6 class=\"wp-block-heading\" id=\"ufw-ubuntu-and-debianbased-linux-distributions\">UFW (Ubuntu and Debian-based Linux distributions):<\/h6>\n\n\n<pre class=\"wp-block-code\"><code>sudo ufw status<\/code><\/pre>\n\n\n\n<p>This command will display the status of the UFW firewall and the list of rules that are configured.<\/p>\n\n\n\n<details class=\"wp-block-details is-layout-flow wp-block-details-is-layout-flow\"><summary>How to allow SSH connections via UFW?<\/summary>\n<p>To allow SSH connections via UFW on a system running Ubuntu or another distribution that uses UFW, follow these steps:<\/p>\n\n\n\n<p>Allow SSH connections in UFW:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo ufw allow ssh<\/code><\/pre>\n\n\n\n<p>Alternatively, you can specify the port number directly (default SSH port is 22):<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo ufw allow 22\/tcp<\/code><\/pre>\n\n\n\n<p>Now check the status of UFW to ensure the rule is added:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo ufw status<\/code><\/pre>\n<\/details>\n\n\n\n<p><\/p>\n\n\n<h6 class=\"wp-block-heading\" id=\"iptables\">IPtables:<\/h6>\n\n\n<pre class=\"wp-block-code\"><code>sudo iptables -L<\/code><\/pre>\n\n\n\n<details class=\"wp-block-details is-layout-flow wp-block-details-is-layout-flow\"><summary>How to allow SSH connections via IPtables?<\/summary>\n<p>To allow SSH connections via <code>iptables<\/code>, you can follow these steps:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo iptables -A INPUT -p tcp --dport 22 -j ACCEPT\n<\/code><\/pre>\n\n\n\n<p>Now save the rules specified now. To save the rules, the command varies with the OS you using.<\/p>\n\n\n\n<p>For Debian-based OS like Ubuntu:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo sh -c \"iptables-save &gt; \/etc\/iptables\/rules.v4\"\nsudo systemctl restart netfilter-persistent<\/code><\/pre>\n\n\n\n<p>For RedHat-based OS like Centos:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo service iptables save\nsudo systemctl restart iptables<\/code><\/pre>\n<\/details>\n\n\n\n<p><\/p>\n\n\n<h6 class=\"wp-block-heading\" id=\"firewalld-red-hat-enterprise-linux-rhel-centos-fedora-and-other-related-distributions\">FirewallD (Red Hat Enterprise Linux (RHEL), CentOS, Fedora, and other related distributions):<\/h6>\n\n\n<pre class=\"wp-block-code\"><code>sudo firewall-cmd --get-active-zones<\/code><\/pre>\n\n\n\n<details class=\"wp-block-details is-layout-flow wp-block-details-is-layout-flow\"><summary>How to allow SSH connections via FirewallD?<\/summary>\n<p>To allow SSH connections via <code>firewalld<\/code>, you can follow these steps:<\/p>\n\n\n\n<p>Start by enabling the SSH service:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo firewall-cmd --permanent --add-service=ssh<\/code><\/pre>\n\n\n\n<p>Now, reload the firewall to apply the changes:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo firewall-cmd --reload<\/code><\/pre>\n<\/details>\n\n\n\n<p><\/p>\n\n\n\n<p>In addition to server-side firewall configurations, consider inspecting network-level firewalls, such as hardware firewalls or cloud security groups, that might be filtering SSH traffic before it reaches the server. Ensure that these network devices are configured to allow SSH connections and that the necessary ports are open for inbound traffic. Collaborate with your network administrators or cloud service providers to adjust the firewall settings and eliminate any port blocking issues hindering the SSH connection.<\/p>\n\n\n\n<p><\/p>\n\n\n<h4 class=\"wp-block-heading\" id=\"checking-ssh-logs\">Checking SSH Logs<\/h4>\n\n\n<p>SSH logs can provide insights into why the connection is being refused. You can use the <code>journalctl<\/code> command to view these logs on systems using <code>systemd<\/code>, or check specific log files directly. Viewing logs via journalctl command is already discussed earlier in this blog.<\/p>\n\n\n\n<p>To check logs directly, open the terminal and run the following command:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo less \/var\/log\/auth.log<\/code><\/pre>\n\n\n\n<p>On some systems, logs are present in a different file, to view it, use the command:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo less \/var\/log\/secure<\/code><\/pre>\n\n\n\n<p>Look for recent entries related to SSH to find any errors or warnings that might explain why the connection is being refused. With these logs you will get an idea of the error and can solve with any of the methods discussed in the blog.<\/p>\n\n\n\n<pre class=\"wp-block-verse\">Tip: When attempting to access a server via SSH from your client machine, you can enhance the verbosity of the SSH command by using the -vvv flag. This flag provides detailed debugging information directly from the client side, helping you to understand the specific errors encountered during the connection process. <br>i.e; <code>ssh -vvv user@hostname_or_ip<\/code><\/pre>\n\n\n\n<p><\/p>\n\n\n<h4 class=\"wp-block-heading\" id=\"troubleshooting-ssh-client-configuration\">Troubleshooting SSH client configuration<\/h4>\n\n\n<p>To resolve the connection refused error, thoroughly examine both server-side and SSH client configurations. The SSH client&#8217;s settings, typically found in ~\/.ssh\/config or \/etc\/ssh\/ssh_config, should be carefully checked for misconfigurations. Pay close attention to any host-specific overrides and ensure correct server IP addresses or hostnames are used, along with appropriate SSH keys. Confirm compatibility of encryption algorithms and key exchange methods with server settings. If issues persist with a particular SSH client, test with an alternative to pinpoint whether the problem is client-specific or broader. By troubleshooting client settings and testing different clients, you can identify and address the underlying cause of the error.<\/p>\n\n\n\n<p>In your local Linux computer, inspect SSH client configuration file with a text editor which will be located at <code>~\/.ssh\/config<\/code> or <code>\/etc\/ssh\/ssh_config<\/code>. This file path is same for macOS but Windows use a different path: <code>C:\\Users\\username.ssh\\config<\/code><\/p>\n\n\n\n<p>Ensure there are no misconfigurations for the specific host you are trying to connect to. An example for the host-specific settings is shown below:<\/p>\n\n\n\n<figure class=\"wp-block-gallery has-nested-images columns-default is-cropped wp-block-gallery-9 is-layout-flex wp-block-gallery-is-layout-flex\">\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/www.veeble.org\/kb\/wp-content\/uploads\/2024\/06\/Screenshot-2024-06-11-214134.png\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" width=\"922\" height=\"111\" data-id=\"3974\" src=\"https:\/\/www.veeble.org\/kb\/wp-content\/uploads\/2024\/06\/Screenshot-2024-06-11-214134.png\" alt=\"\" class=\"wp-image-3974\" srcset=\"https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2024\/06\/Screenshot-2024-06-11-214134.png 922w, https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2024\/06\/Screenshot-2024-06-11-214134-300x36.png 300w, https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2024\/06\/Screenshot-2024-06-11-214134-768x92.png 768w\" sizes=\"(max-width: 922px) 100vw, 922px\" \/><\/a><\/figure>\n<\/figure>\n\n\n\n<p>If you are using key-based authentication to the server, please ensure to provide correct path of the key file in it. Also inspect the preferred encryption algorithms and key exchange methods are correctly set here.<\/p>\n\n\n\n<p>You can also attempt to check the issue by using an alternative SSH client software, such as <a href=\"https:\/\/www.putty.org\/\" target=\"_blank\" rel=\"noopener\">PuTTY<\/a>. Testing the connection through PuTTY can help determine if the problem persists across different client applications.<\/p>\n\n\n\n<p><\/p>\n\n\n<h4 class=\"wp-block-heading\" id=\"reinstalling-ssh-service-and-restarting-the-server\">Reinstalling SSH Service and Restarting the Server<\/h4>\n\n\n<p>If SSH connection refused errors persist despite troubleshooting with the above methods, reinstalling SSH and restarting the server will be the final solution for you.  Before doing it make sure to save work.<\/p>\n\n\n\n<p><strong>On Linux (Ubuntu\/Debian):<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo apt update\nsudo apt install --reinstall openssh-server<\/code><\/pre>\n\n\n\n<p>On Linux (CentOS\/RHEL):<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo yum reinstall openssh-server<\/code><\/pre>\n\n\n\n<div class=\"wp-block-uagb-separator uagb-block-009e6496\"><div class=\"wp-block-uagb-separator__inner\" style=\"--my-background-image:\"><\/div><\/div>\n\n\n\n<p>By systematically applying the approaches discussed in this blog, you can effectively troubleshoot and resolve the &#8216;SSH connection refused&#8217; error, thereby restoring access to your server.<\/p>\n\n\n\n<div style=\"height:25px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<div class=\"wp-block-uagb-call-to-action uagb-block-6f372310 wp-block-button\"><div class=\"uagb-cta__wrap\"><h3 class=\"uagb-cta__title\"><strong>Experience Unbeatable Performance with Fully Managed VPS Hosting<\/strong><\/h3><p class=\"uagb-cta__desc\">Say goodbye to server hassles and hello to blazing-fast performance! Our Managed VPS hosting combines enterprise-grade SSD storage, dedicated resources, and 24\/7 expert monitoring to keep your website or app running smoothly.\u00a0<\/p><\/div><div class=\"uagb-cta__buttons\"><a href=\"https:\/\/www.veeble.com\/in\/managed-vps\/\" class=\"uagb-cta__button-link-wrapper wp-block-button__link\" target=\"_blank\" rel=\"noopener noreferrer\">Choose Your Plan<svg xmlns=\"https:\/\/www.w3.org\/2000\/svg\" viewBox=\"0 0 512 512\"><path d=\"M504.3 273.6l-112.1 104c-6.992 6.484-17.18 8.218-25.94 4.406c-8.758-3.812-14.42-12.45-14.42-21.1L351.9 288H32C14.33 288 .0002 273.7 .0002 255.1S14.33 224 32 224h319.9l0-72c0-9.547 5.66-18.19 14.42-22c8.754-3.809 18.95-2.075 25.94 4.41l112.1 104C514.6 247.9 514.6 264.1 504.3 273.6z\"><\/path><\/svg><\/a><\/div><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Learn how to resolve &#8220;SSH Connection Refused&#8221; error and regain access to the system with our step to step instructions.<\/p>\n","protected":false},"author":7,"featured_media":8519,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_uag_custom_page_level_css":"","site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"set","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[5],"tags":[],"class_list":["post-3937","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-linux"],"uagb_featured_image_src":{"full":["https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2024\/06\/Troubleshooting-SSH-Connection-Refused-Error-and-Regaining-Access.jpg",1536,1024,false],"thumbnail":["https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2024\/06\/Troubleshooting-SSH-Connection-Refused-Error-and-Regaining-Access-150x150.jpg",150,150,true],"medium":["https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2024\/06\/Troubleshooting-SSH-Connection-Refused-Error-and-Regaining-Access-300x200.jpg",300,200,true],"medium_large":["https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2024\/06\/Troubleshooting-SSH-Connection-Refused-Error-and-Regaining-Access-768x512.jpg",768,512,true],"large":["https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2024\/06\/Troubleshooting-SSH-Connection-Refused-Error-and-Regaining-Access-1024x683.jpg",1024,683,true],"1536x1536":["https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2024\/06\/Troubleshooting-SSH-Connection-Refused-Error-and-Regaining-Access.jpg",1536,1024,false],"2048x2048":["https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2024\/06\/Troubleshooting-SSH-Connection-Refused-Error-and-Regaining-Access.jpg",1536,1024,false]},"uagb_author_info":{"display_name":"Adrian Antony","author_link":"https:\/\/www.veeble.com\/kb\/author\/adrian\/"},"uagb_comment_info":0,"uagb_excerpt":"Learn how to resolve \"SSH Connection Refused\" error and regain access to the system with our step to step instructions.","_links":{"self":[{"href":"https:\/\/www.veeble.com\/kb\/wp-json\/wp\/v2\/posts\/3937","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.veeble.com\/kb\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.veeble.com\/kb\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.veeble.com\/kb\/wp-json\/wp\/v2\/users\/7"}],"replies":[{"embeddable":true,"href":"https:\/\/www.veeble.com\/kb\/wp-json\/wp\/v2\/comments?post=3937"}],"version-history":[{"count":37,"href":"https:\/\/www.veeble.com\/kb\/wp-json\/wp\/v2\/posts\/3937\/revisions"}],"predecessor-version":[{"id":7861,"href":"https:\/\/www.veeble.com\/kb\/wp-json\/wp\/v2\/posts\/3937\/revisions\/7861"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.veeble.com\/kb\/wp-json\/wp\/v2\/media\/8519"}],"wp:attachment":[{"href":"https:\/\/www.veeble.com\/kb\/wp-json\/wp\/v2\/media?parent=3937"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.veeble.com\/kb\/wp-json\/wp\/v2\/categories?post=3937"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.veeble.com\/kb\/wp-json\/wp\/v2\/tags?post=3937"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}