{"id":1180,"date":"2024-07-05T06:39:13","date_gmt":"2024-07-05T06:39:13","guid":{"rendered":"https:\/\/zalvis.com\/docs\/?p=1180"},"modified":"2024-07-05T06:39:13","modified_gmt":"2024-07-05T06:39:13","slug":"how-can-i-change-the-port-ssh-listens-on","status":"publish","type":"post","link":"https:\/\/zalvis.com\/docs\/how-can-i-change-the-port-ssh-listens-on.html","title":{"rendered":"How Can I Change the Port SSH Listens On?"},"content":{"rendered":"<p>To change which port ssh listens on, you just need to edit the <strong>sshd_config<\/strong> file. The default directory for ssh configuration is <em>\/etc\/ssh<\/em>.<\/p>\n<ol>\n<li>First, backup the current configuration and use your favorite editor to change the <strong>Port<\/strong> line:<em>root@root [~]# cd \/etc\/ssh\/<\/em><br \/>\n<em>root@root [\/etc\/ssh]# cp sshd_config sshd_config.save<\/em><br \/>\n<em>root@root [\/etc\/ssh]# vi sshd_config<\/em><\/li>\n<li>Now, locate the following line:<em>#Port 22<\/em><\/li>\n<li>For this example, we\u2019ll set it to port 4000, by replacing \u201c<em>Port 22<\/em>\u201d with \u201c<em>Port 4000<\/em>\u201c. <strong>*Note:<\/strong> Do not forget to remove the comment (#).<em>Port 4000<\/em>\n<p><em>root@root [\/etc\/ssh]# diff sshd_config sshd_config.save<\/em><br \/>\n<em>13c13<\/em><br \/>\n<em>&lt; Port 4000<\/em><br \/>\n<em>\u2014<\/em><br \/>\n<em>&gt; #Port 22<\/em><br \/>\n<em>root@root [\/etc\/ssh]#<\/em><\/li>\n<li>Lastly, restart sshd and verify that it is now listening on the new port.<em>root@root [\/etc\/ssh]# \/etc\/init.d\/sshd restart<\/em><br \/>\n<em>Stopping sshd: [ OK ]<\/em><br \/>\n<em>Starting sshd: [ OK ]<\/em><br \/>\n<em>root@root [\/etc\/ssh]# netstat -anp | grep sshd<\/em><br \/>\n<em>tcp 0 0 0.0.0.0:4000 0.0.0.0:* <\/em><br \/>\n<em>LISTEN 1605\/sshd<\/em><\/li>\n<\/ol>\n<p>And there you have it! You can set the port number to whichever port you prefer, but keep in ming that port numbers between 0 and 1,023 are reserved for existing system services. For this reason, you\u2019re typically better off choosing a number above Port 1023.<\/p>\n<div class=\"ktpmg69e7b9c06d808\" >If you enjoyed this article, then you\u2019ll love Zalvis's Cloud Hosting platform. Turbocharge your website and get 24\/7 support from our veteran team. Our world-class hosting infrastructure focuses on auto-scaling, performance, and security. Let us show you the Zalvis difference! <a href=\"https:\/\/zalvis.com\/\">Check out our services.<\/a><\/div><style type=\"text\/css\">\r\n@media screen and (min-width: 1201px) {\r\n.ktpmg69e7b9c06d808 {\r\ndisplay: block;\r\n}\r\n}\r\n@media screen and (min-width: 993px) and (max-width: 1200px) {\r\n.ktpmg69e7b9c06d808 {\r\ndisplay: block;\r\n}\r\n}\r\n@media screen and (min-width: 769px) and (max-width: 992px) {\r\n.ktpmg69e7b9c06d808 {\r\ndisplay: block;\r\n}\r\n}\r\n@media screen and (min-width: 768px) and (max-width: 768px) {\r\n.ktpmg69e7b9c06d808 {\r\ndisplay: block;\r\n}\r\n}\r\n@media screen and (max-width: 767px) {\r\n.ktpmg69e7b9c06d808 {\r\ndisplay: block;\r\n}\r\n}\r\n<\/style>\r\n","protected":false},"excerpt":{"rendered":"<p>To change which port ssh listens on, you just need to edit the sshd_config file. The default directory for ssh configuration is \/etc\/ssh. First, backup the current configuration and use your favorite editor to change the Port line:root@root [~]# cd \/etc\/ssh\/ root@root [\/etc\/ssh]# cp sshd_config sshd_config.save root@root [\/etc\/ssh]# vi sshd_config Now, locate the following line:#Port [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[],"class_list":["post-1180","post","type-post","status-publish","format-standard","hentry","category-server-setup"],"_links":{"self":[{"href":"https:\/\/zalvis.com\/docs\/wp-json\/wp\/v2\/posts\/1180","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/zalvis.com\/docs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/zalvis.com\/docs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/zalvis.com\/docs\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/zalvis.com\/docs\/wp-json\/wp\/v2\/comments?post=1180"}],"version-history":[{"count":2,"href":"https:\/\/zalvis.com\/docs\/wp-json\/wp\/v2\/posts\/1180\/revisions"}],"predecessor-version":[{"id":1182,"href":"https:\/\/zalvis.com\/docs\/wp-json\/wp\/v2\/posts\/1180\/revisions\/1182"}],"wp:attachment":[{"href":"https:\/\/zalvis.com\/docs\/wp-json\/wp\/v2\/media?parent=1180"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/zalvis.com\/docs\/wp-json\/wp\/v2\/categories?post=1180"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/zalvis.com\/docs\/wp-json\/wp\/v2\/tags?post=1180"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}