{"id":440,"date":"2017-02-04T13:03:05","date_gmt":"2017-02-04T11:03:05","guid":{"rendered":"http:\/\/itsimple.info\/?p=440"},"modified":"2017-02-04T13:03:05","modified_gmt":"2017-02-04T11:03:05","slug":"how-to-change-ssh-server-port","status":"publish","type":"post","link":"https:\/\/itsimple.info\/?p=440","title":{"rendered":"How To Change SSH server port"},"content":{"rendered":"<p>&nbsp;<\/p>\n<h4><strong>If you want to change the ssh server port for any reason namely security (extremely recommended), From the default port which is 22 .You can use any other port but above 1024 is preferable.<\/strong><\/h4>\n<p>To change the port on the server, First make a copy :<\/p>\n<pre class=\"wp-code-highlight prettyprint prettyprinted\"><span class=\"pln\">cp <\/span><span class=\"pun\">-<\/span><span class=\"pln\">p <\/span><span class=\"pun\">\/<\/span><span class=\"pln\">etc<\/span><span class=\"pun\">\/<\/span><span class=\"pln\">ssh<\/span><span class=\"pun\">\/<\/span><span class=\"pln\">sshd_config <\/span><span class=\"pun\">\/<\/span><span class=\"pln\">etc<\/span><span class=\"pun\">\/<\/span><span class=\"pln\">ssh<\/span><span class=\"pun\">\/<\/span><span class=\"pln\">sshd_config<\/span><span class=\"pun\">.<\/span><span class=\"pln\">orig<\/span><span class=\"pun\">.<\/span><span class=\"pln\">$<\/span><span class=\"pun\">(<\/span><span class=\"pln\">date <\/span><span class=\"pun\">+%<\/span><span class=\"pln\">F<\/span><span class=\"pun\">)<\/span><\/pre>\n<p>Then change the port to &#8230; for example 2222 :<\/p>\n<pre>nano \/etc\/ssh\/sshd_config<\/pre>\n<p>Unmark the #port 22\u00a0 to\u00a0 port 2222<\/p>\n<p>Also allow it through the SElinux :<\/p>\n<pre class=\"wp-code-highlight prettyprint prettyprinted\"><span class=\"pln\">semanage port <\/span><span class=\"pun\">-<\/span><span class=\"pln\">a <\/span><span class=\"pun\">-<\/span><span class=\"pln\">t <\/span><span class=\"typ\">ssh_port_t<\/span> <span class=\"pun\">-<\/span><span class=\"pln\">p tcp <\/span><span class=\"lit\">2222<\/span><\/pre>\n<p>Note: if you get &#8220;semanage command unknown&#8221; you should install the tool with YUM, this will add the option :<\/p>\n<pre class=\"wp-code-highlight prettyprint prettyprinted\"><span class=\"pln\">yum install policycoreutils<\/span><span class=\"pun\">-<\/span><span class=\"pln\">python<\/span><\/pre>\n<p>Now add the port to the firewall rules:<\/p>\n<pre>firewall-cmd --zone=public --add-port=2222\/tcp --permanent<\/pre>\n<p>List all rules to make sure you did good :<\/p>\n<pre>firewall-cmd --list-all<\/pre>\n<p>Reload the firewall to apply the rules:<\/p>\n<pre>firewall-cmd --reload<\/pre>\n<p>Restart SSH to apply the changes:<\/p>\n<pre>systemctl restart sshd<\/pre>\n<p>&nbsp;<\/p>\n<hr \/>\n<p class=\"wp-code-highlight prettyprint prettyprinted\"><span class=\"lit\">Good Luck <\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>&nbsp; If you want to change the ssh server port for any reason namely security (extremely recommended), From the default port which is 22 .You can use any other port but above 1024 is preferable. To change the port on the server, First make a copy : cp -p \/etc\/ssh\/sshd_config \/etc\/ssh\/sshd_config.orig.$(date +%F) Then change the [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16,13,22,12],"tags":[],"class_list":["post-440","post","type-post","status-publish","format-standard","hentry","category-centos","category-linux","category-security","category-tutorials"],"_links":{"self":[{"href":"https:\/\/itsimple.info\/index.php?rest_route=\/wp\/v2\/posts\/440","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/itsimple.info\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/itsimple.info\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/itsimple.info\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/itsimple.info\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=440"}],"version-history":[{"count":0,"href":"https:\/\/itsimple.info\/index.php?rest_route=\/wp\/v2\/posts\/440\/revisions"}],"wp:attachment":[{"href":"https:\/\/itsimple.info\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=440"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/itsimple.info\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=440"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/itsimple.info\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=440"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}