{"id":2069,"date":"2021-06-10T15:43:15","date_gmt":"2021-06-10T12:43:15","guid":{"rendered":"https:\/\/www.scalahosting.com\/kb\/?p=2069"},"modified":"2022-03-11T11:39:24","modified_gmt":"2022-03-11T09:39:24","slug":"changing-default-ssh-port-in-openssh","status":"publish","type":"post","link":"https:\/\/www.scalahosting.com\/kb\/changing-default-ssh-port-in-openssh\/","title":{"rendered":"Changing default SSH port in OpenSSH"},"content":{"rendered":"<p><b>Most servers will retain the default SSH port number as 22<\/b><span style=\"font-weight: 400;\">. However, in some cases, this may be changed by administrators as a security enhancement. If you wish to change the SSH port to an alternate number, one way of doing so is by using <\/span><b>OpenSSH.<\/b><\/p>\n<h2><span style=\"font-weight: 400;\">How to Change the Default SSH Port in OpenSSH<\/span><\/h2>\n<p><span style=\"font-weight: 400;\">The process involves locating the server <\/span><b>SSH configuration file <\/b><span style=\"font-weight: 400;\">and amending the port number within that file.<\/span><\/p>\n<p><img decoding=\"async\" class=\"aligncenter size-full wp-image-2070\" src=\"https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2021\/06\/vi-port-edit.jpg\" alt=\"Changing default SSH port in OpenSSH, How to Change the Default SSH Port in OpenSSH\" width=\"745\" height=\"414\" srcset=\"https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2021\/06\/vi-port-edit.jpg 745w, https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2021\/06\/vi-port-edit-300x167.jpg 300w\" sizes=\"(max-width: 361px) 660px, (max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 910px, 1140px\" \/><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>Step 1.<\/b><span style=\"font-weight: 400;\"> Connect to your server as a root user and open the <\/span><a href=\"https:\/\/www.scalahosting.com\/blog\/what-is-ssh-and-how-to-use-it\/\"><b>SSH<\/b><\/a><span style=\"font-weight: 400;\"> configuration file for editing. The command you use will vary depending on the text editor used. For this example, we\u2019ll be using Vi. Enter the<\/span><b> following command:<\/b><\/li>\n<\/ul>\n<p><b>$ vi \/etc\/ssh\/sshd_config<\/b><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>Step 2.<\/b><span style=\"font-weight: 400;\"> Search for the line which specifies your <\/span><b>SSH port number<\/b><span style=\"font-weight: 400;\">, then change the port to a preferred number and remove the <em>#<\/em> to uncomment the line. Bear in mind that the new port must be opened by the server&#8217;s firewall. If it isn&#8217;t, connecting to the server via SSH would be impossible. Remember to save the file before exiting.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>Step 3.<\/b><span style=\"font-weight: 400;\"> Once the port number has been changed the <\/span><b>SSH service needs<\/b><span style=\"font-weight: 400;\"> to be restarted for those changes to take effect. To restart the service:<\/span><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400;\">For CentOS\/Fedora: <\/span> <b>\u201cservice sshd restart\u201d<\/b><\/p>\n<p><span style=\"font-weight: 400;\">For Debian\/Ubuntu: <\/span> <b>\u201cservice ssh restart\u201d<\/b><\/p>\n<p><span style=\"font-weight: 400;\">A message should <\/span><b>appear indicating that the SSH service<\/b><span style=\"font-weight: 400;\"> was stopped and restarted correctly.<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>Step 4.<\/b><span style=\"font-weight: 400;\"> Verify that the port number change has taken effect by entering the following command:<\/span><\/li>\n<\/ul>\n<p><b>ps aux | grep sshd<\/b><\/p>\n<p><span style=\"font-weight: 400;\">You should see a message indicating<\/span><b> the SSH status<\/b><span style=\"font-weight: 400;\"> as well as the new port number for which it is listening to connections.<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Most servers will retain the default SSH port number as 22. However, in some cases, this may be changed by administrators as a security enhancement. If you wish to change the SSH port to an alternate number, one way of doing so is by using OpenSSH. How to Change the Default SSH Port in OpenSSH [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"_seopress_robots_primary_cat":"","_seopress_titles_title":"","_seopress_titles_desc":"","_seopress_robots_index":"","footnotes":""},"categories":[34],"tags":[],"class_list":["post-2069","post","type-post","status-publish","format-standard","hentry","category-web-hosting"],"acf":[],"_links":{"self":[{"href":"https:\/\/www.scalahosting.com\/kb\/wp-json\/wp\/v2\/posts\/2069","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.scalahosting.com\/kb\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.scalahosting.com\/kb\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.scalahosting.com\/kb\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/www.scalahosting.com\/kb\/wp-json\/wp\/v2\/comments?post=2069"}],"version-history":[{"count":3,"href":"https:\/\/www.scalahosting.com\/kb\/wp-json\/wp\/v2\/posts\/2069\/revisions"}],"predecessor-version":[{"id":3916,"href":"https:\/\/www.scalahosting.com\/kb\/wp-json\/wp\/v2\/posts\/2069\/revisions\/3916"}],"wp:attachment":[{"href":"https:\/\/www.scalahosting.com\/kb\/wp-json\/wp\/v2\/media?parent=2069"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.scalahosting.com\/kb\/wp-json\/wp\/v2\/categories?post=2069"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.scalahosting.com\/kb\/wp-json\/wp\/v2\/tags?post=2069"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}