{"id":2128,"date":"2015-04-07T13:27:57","date_gmt":"2015-04-07T13:27:57","guid":{"rendered":"https:\/\/qbytes.cloud\/?p=2128"},"modified":"2015-04-07T13:27:57","modified_gmt":"2015-04-07T13:27:57","slug":"add-different-port-ssh-centos-7","status":"publish","type":"post","link":"https:\/\/www.qbytes.cloud\/index.php\/2015\/04\/07\/add-different-port-ssh-centos-7\/","title":{"rendered":"Add different port ssh CentOS 7"},"content":{"rendered":"<p>Begin by opening the configuration file with your text editor as root:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\n\n# nano \/etc\/ssh\/sshd_config\n\n<\/pre>\n<p>The first option that you may want to change is the port that SSH runs on. Find the line that looks like this:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\n\n#Port 22\n\n<\/pre>\n<p>Change this to a different port<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\n\n#Port 2244\n\n<\/pre>\n<p>Reload ssh<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\n# systemctl reload sshd.service\n<\/pre>\n<p>After saving, don\u2019t exit until you\u2019ve completed these steps.<\/p>\n<p>By default, SELinux only allows port 22 for SSH. What you need to do is enable the newly created port through SELinux. To do that, run the commands below<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\n\n# sudo semanage port -a -t ssh_port_t -p tcp 2244\n\n<\/pre>\n<p>If you run the commands above and get an error that semanage command not found, run the commands below to install it.<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\n\n# sudo yum -y install policycoreutils-python\n\n<\/pre>\n<p>Then go and run the semange commend again to allow the new port through SELinux.<\/p>\n<p>Note: CentOS8<\/p>\n<p>In CentOS or RHEL Linux based distributions, install policycoreutils package and add the below rules to relax SELinux policy in order for the SSH daemon to bind on the new port.<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\n# yum install policycoreutils\n# semanage port -a -t ssh_port_t -p tcp 34627\n# semanage port -m -t ssh_port_t -p tcp 34627\n# systemctl restart sshd\n# netstat -tlpn| grep ssh\n# ss -tlpn| grep ssh\n<\/pre>\n<p>After that, run the commands below to allow the new port through the firewall.<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\n\n# sudo firewall-cmd --permanent --zone=public --add-port=2244\/tcp\n\n<\/pre>\n<p>Reload the firewall configurations<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\n\n# sudo firewall-cmd --reload\n\n<\/pre>\n<p>Restart SSH by  running the commands below.<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\n\n# sudo systemctl restart sshd.service\n\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Begin by opening the configuration file with your text editor as root: # nano \/etc\/ssh\/sshd_config The first option that you may want to change is the port that SSH runs on. Find the line that looks like this: #Port 22 Change this to a different port #Port 2244 Reload ssh # systemctl reload sshd.service After &#8230; <a title=\"Add different port ssh CentOS 7\" class=\"read-more\" href=\"https:\/\/www.qbytes.cloud\/index.php\/2015\/04\/07\/add-different-port-ssh-centos-7\/\" aria-label=\"Read more about Add different port ssh CentOS 7\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12],"tags":[],"class_list":["post-2128","post","type-post","status-publish","format-standard","hentry","category-centos-7"],"_links":{"self":[{"href":"https:\/\/www.qbytes.cloud\/index.php\/wp-json\/wp\/v2\/posts\/2128","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.qbytes.cloud\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.qbytes.cloud\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.qbytes.cloud\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.qbytes.cloud\/index.php\/wp-json\/wp\/v2\/comments?post=2128"}],"version-history":[{"count":0,"href":"https:\/\/www.qbytes.cloud\/index.php\/wp-json\/wp\/v2\/posts\/2128\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.qbytes.cloud\/index.php\/wp-json\/wp\/v2\/media?parent=2128"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.qbytes.cloud\/index.php\/wp-json\/wp\/v2\/categories?post=2128"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.qbytes.cloud\/index.php\/wp-json\/wp\/v2\/tags?post=2128"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}