
{"id":1607,"date":"2025-10-20T21:47:01","date_gmt":"2025-10-20T21:47:01","guid":{"rendered":"https:\/\/www.fastpanda.co.uk\/knowledge-hub\/?p=1607"},"modified":"2025-11-04T19:09:37","modified_gmt":"2025-11-04T19:09:37","slug":"how-to-change-the-ssh-port-on-ubuntu-debian","status":"publish","type":"post","link":"https:\/\/www.fastpanda.co.uk\/knowledge-hub\/how-to-change-the-ssh-port-on-ubuntu-debian\/","title":{"rendered":"How to Change the SSH Port on Ubuntu\/Debian?"},"content":{"rendered":"<p data-start=\"0\" data-end=\"138\">The default SSH port can be changed by server administrators for various reasons. The main reasons for changing the port are as follows:<\/p>\n<ul>\n<li data-start=\"140\" data-end=\"434\"><strong data-start=\"140\" data-end=\"161\">Security Measure:<\/strong><br data-start=\"161\" data-end=\"164\" \/>Default SSH ports are constantly scanned by bots on the internet. This causes systems using the standard port to be frequently targeted by password-guessing attacks. To enhance security, server administrators may change the SSH port to reduce the risk of such attacks.<\/li>\n<li data-start=\"436\" data-end=\"644\"><strong data-start=\"436\" data-end=\"461\">Network Restrictions:<\/strong><br data-start=\"461\" data-end=\"464\" \/>In some organizations or networks, the use of standard ports may be blocked for security reasons. In such cases, a different port must be selected to establish an SSH connection.<\/li>\n<li data-start=\"646\" data-end=\"783\"><strong data-start=\"646\" data-end=\"676\">Preventing Port Conflicts:<\/strong><br data-start=\"676\" data-end=\"679\" \/>If another service on the server uses the same port, the SSH port may be changed to prevent conflicts.<\/li>\n<\/ul>\n<p data-start=\"785\" data-end=\"895\" data-is-last-node=\"\" data-is-only-node=\"\">For the reasons mentioned above or similar ones you can follow the steps below to safely change your SSH port.<\/p>\n<ul>\n<li data-start=\"785\" data-end=\"895\">Log in to the server. <a href=\"https:\/\/www.fastpanda.co.uk\/knowledge-hub\/how-to-connect-to-a-linux-server-from-a-windows-computer\/\" target=\"_blank\" rel=\"noopener\">If you are not familiar with the steps to access the server, click here to read our guide<\/a>. The following steps use PuTTY as an example.<\/li>\n<li>Back up the <strong data-start=\"12\" data-end=\"27\">sshd_config<\/strong> file. Since you will be making changes to the port and security settings, any mistake could prevent you from accessing the server via SSH. Therefore, it is recommended to create a backup beforehand. To back it up, copy the command below, right-click to paste it into the server after connecting, and press Enter.<br \/>\n<b>sudo cp \/etc\/ssh\/sshd_config \/etc\/ssh\/sshd_config.bak<br \/>\n<\/b><a href=\"https:\/\/www.fastpanda.co.uk\/knowledge-hub\/wp-content\/uploads\/2025\/10\/Back-up-sshd_config.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1595\" title=\"Back up sshd_config\" src=\"https:\/\/www.fastpanda.co.uk\/knowledge-hub\/wp-content\/uploads\/2025\/10\/Back-up-sshd_config.png\" alt=\"Back up sshd config\" width=\"1914\" height=\"1003\" srcset=\"https:\/\/www.fastpanda.co.uk\/knowledge-hub\/wp-content\/uploads\/2025\/10\/Back-up-sshd_config.png 1914w, https:\/\/www.fastpanda.co.uk\/knowledge-hub\/wp-content\/uploads\/2025\/10\/Back-up-sshd_config-300x157.png 300w, https:\/\/www.fastpanda.co.uk\/knowledge-hub\/wp-content\/uploads\/2025\/10\/Back-up-sshd_config-1024x537.png 1024w, https:\/\/www.fastpanda.co.uk\/knowledge-hub\/wp-content\/uploads\/2025\/10\/Back-up-sshd_config-768x402.png 768w, https:\/\/www.fastpanda.co.uk\/knowledge-hub\/wp-content\/uploads\/2025\/10\/Back-up-sshd_config-1536x805.png 1536w, https:\/\/www.fastpanda.co.uk\/knowledge-hub\/wp-content\/uploads\/2025\/10\/Back-up-sshd_config-60x31.png 60w, https:\/\/www.fastpanda.co.uk\/knowledge-hub\/wp-content\/uploads\/2025\/10\/Back-up-sshd_config-150x79.png 150w\" sizes=\"(max-width: 1914px) 100vw, 1914px\" \/><\/a><\/li>\n<li>To open the SSH configuration file, copy the command below, right-click to paste it into the server, and press Enter.<br \/>\n<strong>sudo nano \/etc\/ssh\/sshd_config<br \/>\n<\/strong><a href=\"https:\/\/www.fastpanda.co.uk\/knowledge-hub\/wp-content\/uploads\/2025\/10\/SSH-configuration-file.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1596\" title=\"SSH configuration file\" src=\"https:\/\/www.fastpanda.co.uk\/knowledge-hub\/wp-content\/uploads\/2025\/10\/SSH-configuration-file.png\" alt=\"SSH configuration file\" width=\"1901\" height=\"1008\" srcset=\"https:\/\/www.fastpanda.co.uk\/knowledge-hub\/wp-content\/uploads\/2025\/10\/SSH-configuration-file.png 1901w, https:\/\/www.fastpanda.co.uk\/knowledge-hub\/wp-content\/uploads\/2025\/10\/SSH-configuration-file-300x159.png 300w, https:\/\/www.fastpanda.co.uk\/knowledge-hub\/wp-content\/uploads\/2025\/10\/SSH-configuration-file-1024x543.png 1024w, https:\/\/www.fastpanda.co.uk\/knowledge-hub\/wp-content\/uploads\/2025\/10\/SSH-configuration-file-768x407.png 768w, https:\/\/www.fastpanda.co.uk\/knowledge-hub\/wp-content\/uploads\/2025\/10\/SSH-configuration-file-1536x814.png 1536w, https:\/\/www.fastpanda.co.uk\/knowledge-hub\/wp-content\/uploads\/2025\/10\/SSH-configuration-file-60x32.png 60w, https:\/\/www.fastpanda.co.uk\/knowledge-hub\/wp-content\/uploads\/2025\/10\/SSH-configuration-file-150x80.png 150w\" sizes=\"(max-width: 1901px) 100vw, 1901px\" \/><\/a><\/li>\n<li data-start=\"785\" data-end=\"895\">\n<p data-start=\"0\" data-end=\"367\">Locate the line that says Port 22667 in the file. (It may show a different port number instead of 22667.) Replace 22667 with your desired port number, for example, 6000. Similarly, update the Listen Address information with your desired port.\u00a0<br data-start=\"164\" data-end=\"167\" \/>If there is a \u201c#\u201d at the beginning of the Port line, remove it, because # is treated as a comment and the new port may not take effect. To save, press Ctrl + O and then Enter. Immediately after, press Ctrl + X to exit.<\/p>\n<ul>\n<li data-start=\"785\" data-end=\"895\">\n<p data-start=\"0\" data-end=\"367\">Valid range: 0 &#8211; 65535<\/p>\n<\/li>\n<li data-start=\"785\" data-end=\"895\">\n<p data-start=\"0\" data-end=\"367\">0 &#8211; 1023: Reserved for the operating system and core services. Manual use is not recommended. Examples: 22 (SSH), 80 (HTTP), 443 (HTTPS)<\/p>\n<\/li>\n<li data-start=\"785\" data-end=\"895\">\n<p data-start=\"0\" data-end=\"367\">1024 &#8211; 49151: Registered ports used by software; usually okay to use. Examples: 3306 (MySQL), 3389 (RDP)<\/p>\n<\/li>\n<li data-start=\"785\" data-end=\"895\">\n<p data-start=\"0\" data-end=\"367\">49152 &#8211; 65535: Usually free ports. This range is the safest choice for your own services.<br \/>\n<a href=\"https:\/\/www.fastpanda.co.uk\/knowledge-hub\/wp-content\/uploads\/2025\/10\/Ubuntu-Port-Change.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1616\" title=\"Ubuntu Port Change\" src=\"https:\/\/www.fastpanda.co.uk\/knowledge-hub\/wp-content\/uploads\/2025\/10\/Ubuntu-Port-Change.png\" alt=\"Ubuntu Port Change\" width=\"1902\" height=\"1010\" srcset=\"https:\/\/www.fastpanda.co.uk\/knowledge-hub\/wp-content\/uploads\/2025\/10\/Ubuntu-Port-Change.png 1902w, https:\/\/www.fastpanda.co.uk\/knowledge-hub\/wp-content\/uploads\/2025\/10\/Ubuntu-Port-Change-300x159.png 300w, https:\/\/www.fastpanda.co.uk\/knowledge-hub\/wp-content\/uploads\/2025\/10\/Ubuntu-Port-Change-1024x544.png 1024w, https:\/\/www.fastpanda.co.uk\/knowledge-hub\/wp-content\/uploads\/2025\/10\/Ubuntu-Port-Change-768x408.png 768w, https:\/\/www.fastpanda.co.uk\/knowledge-hub\/wp-content\/uploads\/2025\/10\/Ubuntu-Port-Change-1536x816.png 1536w, https:\/\/www.fastpanda.co.uk\/knowledge-hub\/wp-content\/uploads\/2025\/10\/Ubuntu-Port-Change-60x32.png 60w, https:\/\/www.fastpanda.co.uk\/knowledge-hub\/wp-content\/uploads\/2025\/10\/Ubuntu-Port-Change-150x80.png 150w\" sizes=\"(max-width: 1902px) 100vw, 1902px\" \/><\/a><\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>To test the configuration, paste the command below. If no errors appear, you can proceed to the next steps.<br \/>\n<strong>sudo sshd -t &gt; Enter<br \/>\n<a href=\"https:\/\/www.fastpanda.co.uk\/knowledge-hub\/wp-content\/uploads\/2025\/10\/test-the-configuration.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1599\" title=\"test the configuration\" src=\"https:\/\/www.fastpanda.co.uk\/knowledge-hub\/wp-content\/uploads\/2025\/10\/test-the-configuration.png\" alt=\"test the configuration\" width=\"1900\" height=\"1006\" srcset=\"https:\/\/www.fastpanda.co.uk\/knowledge-hub\/wp-content\/uploads\/2025\/10\/test-the-configuration.png 1900w, https:\/\/www.fastpanda.co.uk\/knowledge-hub\/wp-content\/uploads\/2025\/10\/test-the-configuration-300x159.png 300w, https:\/\/www.fastpanda.co.uk\/knowledge-hub\/wp-content\/uploads\/2025\/10\/test-the-configuration-1024x542.png 1024w, https:\/\/www.fastpanda.co.uk\/knowledge-hub\/wp-content\/uploads\/2025\/10\/test-the-configuration-768x407.png 768w, https:\/\/www.fastpanda.co.uk\/knowledge-hub\/wp-content\/uploads\/2025\/10\/test-the-configuration-1536x813.png 1536w, https:\/\/www.fastpanda.co.uk\/knowledge-hub\/wp-content\/uploads\/2025\/10\/test-the-configuration-60x32.png 60w, https:\/\/www.fastpanda.co.uk\/knowledge-hub\/wp-content\/uploads\/2025\/10\/test-the-configuration-150x79.png 150w\" sizes=\"(max-width: 1900px) 100vw, 1900px\" \/><\/a><\/strong><\/li>\n<li>If UFW is not active, you need to enable it first. Copy and paste the following command, then press Enter. A warning will appear on the screen. Press the <strong>Y<\/strong> key on your keyboard and then press Enter.<br \/>\n<strong>sudo ufw enable<\/strong><br \/>\n<a href=\"https:\/\/www.fastpanda.co.uk\/knowledge-hub\/wp-content\/uploads\/2025\/10\/sudo-ufw-enable.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1611\" title=\"sudo ufw enable\" src=\"https:\/\/www.fastpanda.co.uk\/knowledge-hub\/wp-content\/uploads\/2025\/10\/sudo-ufw-enable.png\" alt=\"sudo ufw enable\" width=\"1905\" height=\"1010\" srcset=\"https:\/\/www.fastpanda.co.uk\/knowledge-hub\/wp-content\/uploads\/2025\/10\/sudo-ufw-enable.png 1905w, https:\/\/www.fastpanda.co.uk\/knowledge-hub\/wp-content\/uploads\/2025\/10\/sudo-ufw-enable-300x159.png 300w, https:\/\/www.fastpanda.co.uk\/knowledge-hub\/wp-content\/uploads\/2025\/10\/sudo-ufw-enable-1024x543.png 1024w, https:\/\/www.fastpanda.co.uk\/knowledge-hub\/wp-content\/uploads\/2025\/10\/sudo-ufw-enable-768x407.png 768w, https:\/\/www.fastpanda.co.uk\/knowledge-hub\/wp-content\/uploads\/2025\/10\/sudo-ufw-enable-1536x814.png 1536w, https:\/\/www.fastpanda.co.uk\/knowledge-hub\/wp-content\/uploads\/2025\/10\/sudo-ufw-enable-60x32.png 60w, https:\/\/www.fastpanda.co.uk\/knowledge-hub\/wp-content\/uploads\/2025\/10\/sudo-ufw-enable-150x80.png 150w\" sizes=\"(max-width: 1905px) 100vw, 1905px\" \/><\/a><\/li>\n<li>Paste the following commands one by one to add the new port to the firewall.<br \/>\n<strong>sudo ufw allow 6000\/tcp &gt; Enter<br \/>\nsudo ufw reload &gt; Enter<br \/>\n<\/strong><a href=\"https:\/\/www.fastpanda.co.uk\/knowledge-hub\/wp-content\/uploads\/2025\/10\/sudo-ufw-reload.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1613\" title=\"sudo ufw reload\" src=\"https:\/\/www.fastpanda.co.uk\/knowledge-hub\/wp-content\/uploads\/2025\/10\/sudo-ufw-reload.png\" alt=\"sudo ufw reload\" width=\"1904\" height=\"1007\" srcset=\"https:\/\/www.fastpanda.co.uk\/knowledge-hub\/wp-content\/uploads\/2025\/10\/sudo-ufw-reload.png 1904w, https:\/\/www.fastpanda.co.uk\/knowledge-hub\/wp-content\/uploads\/2025\/10\/sudo-ufw-reload-300x159.png 300w, https:\/\/www.fastpanda.co.uk\/knowledge-hub\/wp-content\/uploads\/2025\/10\/sudo-ufw-reload-1024x542.png 1024w, https:\/\/www.fastpanda.co.uk\/knowledge-hub\/wp-content\/uploads\/2025\/10\/sudo-ufw-reload-768x406.png 768w, https:\/\/www.fastpanda.co.uk\/knowledge-hub\/wp-content\/uploads\/2025\/10\/sudo-ufw-reload-1536x812.png 1536w, https:\/\/www.fastpanda.co.uk\/knowledge-hub\/wp-content\/uploads\/2025\/10\/sudo-ufw-reload-60x32.png 60w, https:\/\/www.fastpanda.co.uk\/knowledge-hub\/wp-content\/uploads\/2025\/10\/sudo-ufw-reload-150x79.png 150w\" sizes=\"(max-width: 1904px) 100vw, 1904px\" \/><\/a><\/li>\n<li>To check, paste the following command and press Enter. Your new port should appear in the list (e.g., 6000).<br \/>\n<strong>sudo ufw status<\/strong><br \/>\n<a href=\"https:\/\/www.fastpanda.co.uk\/knowledge-hub\/wp-content\/uploads\/2025\/10\/sudo-ufw-status.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1614\" title=\"sudo ufw status\" src=\"https:\/\/www.fastpanda.co.uk\/knowledge-hub\/wp-content\/uploads\/2025\/10\/sudo-ufw-status.png\" alt=\"sudo ufw status\" width=\"1904\" height=\"1004\" srcset=\"https:\/\/www.fastpanda.co.uk\/knowledge-hub\/wp-content\/uploads\/2025\/10\/sudo-ufw-status.png 1904w, https:\/\/www.fastpanda.co.uk\/knowledge-hub\/wp-content\/uploads\/2025\/10\/sudo-ufw-status-300x158.png 300w, https:\/\/www.fastpanda.co.uk\/knowledge-hub\/wp-content\/uploads\/2025\/10\/sudo-ufw-status-1024x540.png 1024w, https:\/\/www.fastpanda.co.uk\/knowledge-hub\/wp-content\/uploads\/2025\/10\/sudo-ufw-status-768x405.png 768w, https:\/\/www.fastpanda.co.uk\/knowledge-hub\/wp-content\/uploads\/2025\/10\/sudo-ufw-status-1536x810.png 1536w, https:\/\/www.fastpanda.co.uk\/knowledge-hub\/wp-content\/uploads\/2025\/10\/sudo-ufw-status-60x32.png 60w, https:\/\/www.fastpanda.co.uk\/knowledge-hub\/wp-content\/uploads\/2025\/10\/sudo-ufw-status-150x79.png 150w\" sizes=\"(max-width: 1904px) 100vw, 1904px\" \/><\/a><\/li>\n<li data-start=\"785\" data-end=\"895\">To restart the SSH service, copy and paste the following command, then press Enter.<br \/>\n<strong>sudo systemctl restart ssh<\/strong><br \/>\n<a href=\"https:\/\/www.fastpanda.co.uk\/knowledge-hub\/wp-content\/uploads\/2025\/10\/sudo-systemctl-restart-ssh.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1615\" title=\"sudo systemctl restart ssh\" src=\"https:\/\/www.fastpanda.co.uk\/knowledge-hub\/wp-content\/uploads\/2025\/10\/sudo-systemctl-restart-ssh.png\" alt=\"sudo systemctl restart ssh\" width=\"1898\" height=\"1009\" srcset=\"https:\/\/www.fastpanda.co.uk\/knowledge-hub\/wp-content\/uploads\/2025\/10\/sudo-systemctl-restart-ssh.png 1898w, https:\/\/www.fastpanda.co.uk\/knowledge-hub\/wp-content\/uploads\/2025\/10\/sudo-systemctl-restart-ssh-300x159.png 300w, https:\/\/www.fastpanda.co.uk\/knowledge-hub\/wp-content\/uploads\/2025\/10\/sudo-systemctl-restart-ssh-1024x544.png 1024w, https:\/\/www.fastpanda.co.uk\/knowledge-hub\/wp-content\/uploads\/2025\/10\/sudo-systemctl-restart-ssh-768x408.png 768w, https:\/\/www.fastpanda.co.uk\/knowledge-hub\/wp-content\/uploads\/2025\/10\/sudo-systemctl-restart-ssh-1536x817.png 1536w, https:\/\/www.fastpanda.co.uk\/knowledge-hub\/wp-content\/uploads\/2025\/10\/sudo-systemctl-restart-ssh-60x32.png 60w, https:\/\/www.fastpanda.co.uk\/knowledge-hub\/wp-content\/uploads\/2025\/10\/sudo-systemctl-restart-ssh-150x80.png 150w\" sizes=\"(max-width: 1898px) 100vw, 1898px\" \/><\/a><\/li>\n<li>To test access, do not close your current PuTTY session. Open a new PuTTY window, enter your new port number (e.g., 6000) in the &#8220;Port&#8221; field, and try to connect. If the connection is successful, SSH is now running on the new port.<br \/>\n<a href=\"https:\/\/www.fastpanda.co.uk\/knowledge-hub\/wp-content\/uploads\/2025\/10\/Putty-Port.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1602\" title=\"Putty Port\" src=\"https:\/\/www.fastpanda.co.uk\/knowledge-hub\/wp-content\/uploads\/2025\/10\/Putty-Port.png\" alt=\"Putty Port\" width=\"1919\" height=\"875\" srcset=\"https:\/\/www.fastpanda.co.uk\/knowledge-hub\/wp-content\/uploads\/2025\/10\/Putty-Port.png 1919w, https:\/\/www.fastpanda.co.uk\/knowledge-hub\/wp-content\/uploads\/2025\/10\/Putty-Port-300x137.png 300w, https:\/\/www.fastpanda.co.uk\/knowledge-hub\/wp-content\/uploads\/2025\/10\/Putty-Port-1024x467.png 1024w, https:\/\/www.fastpanda.co.uk\/knowledge-hub\/wp-content\/uploads\/2025\/10\/Putty-Port-768x350.png 768w, https:\/\/www.fastpanda.co.uk\/knowledge-hub\/wp-content\/uploads\/2025\/10\/Putty-Port-1536x700.png 1536w, https:\/\/www.fastpanda.co.uk\/knowledge-hub\/wp-content\/uploads\/2025\/10\/Putty-Port-60x27.png 60w, https:\/\/www.fastpanda.co.uk\/knowledge-hub\/wp-content\/uploads\/2025\/10\/Putty-Port-150x68.png 150w\" sizes=\"(max-width: 1919px) 100vw, 1919px\" \/><\/a><\/li>\n<li data-start=\"785\" data-end=\"895\">If you wish, you can remove the old port from the firewall. To do this, simply paste the following command and press Enter.<br \/>\n<strong>sudo ufw delete allow 22667\/tcp\u00a0<\/strong> (You can replace 22667 with your own old port number.)<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>The default SSH port can be changed by server administrators for various reasons. The main reasons for changing the port are as follows: Security Measure:Default SSH ports are constantly scanned by bots on the internet. This causes systems using the standard port to be frequently targeted by password-guessing attacks. To enhance security, server administrators may [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12],"tags":[],"_links":{"self":[{"href":"https:\/\/www.fastpanda.co.uk\/knowledge-hub\/wp-json\/wp\/v2\/posts\/1607"}],"collection":[{"href":"https:\/\/www.fastpanda.co.uk\/knowledge-hub\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.fastpanda.co.uk\/knowledge-hub\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.fastpanda.co.uk\/knowledge-hub\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/www.fastpanda.co.uk\/knowledge-hub\/wp-json\/wp\/v2\/comments?post=1607"}],"version-history":[{"count":5,"href":"https:\/\/www.fastpanda.co.uk\/knowledge-hub\/wp-json\/wp\/v2\/posts\/1607\/revisions"}],"predecessor-version":[{"id":1660,"href":"https:\/\/www.fastpanda.co.uk\/knowledge-hub\/wp-json\/wp\/v2\/posts\/1607\/revisions\/1660"}],"wp:attachment":[{"href":"https:\/\/www.fastpanda.co.uk\/knowledge-hub\/wp-json\/wp\/v2\/media?parent=1607"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.fastpanda.co.uk\/knowledge-hub\/wp-json\/wp\/v2\/categories?post=1607"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.fastpanda.co.uk\/knowledge-hub\/wp-json\/wp\/v2\/tags?post=1607"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}