{"id":978,"date":"2018-10-22T15:45:07","date_gmt":"2018-10-22T08:45:07","guid":{"rendered":"https:\/\/www.whplus.com\/blog\/?p=978"},"modified":"2018-11-12T15:50:06","modified_gmt":"2018-11-12T08:50:06","slug":"how-to-change-ssh-port-on-centos-7","status":"publish","type":"post","link":"https:\/\/www.whplus.com\/blog\/2018\/10\/22\/how-to-change-ssh-port-on-centos-7.html","title":{"rendered":"How To Change SSH Port On CentOS 7"},"content":{"rendered":"<p>To change the default SSH port, the first thing you want to do is backup the current SSH configuration on your system. To do that, run the commands below.<\/p>\n<p><code>cp \/etc\/ssh\/sshd_config \/etc\/ssh\/sshd_config.bak<\/code><\/p>\n<p>Next, run the commands below to open the default SSH configuration file<\/p>\n<p><code>sudo vi \/etc\/ssh\/sshd_config<\/code><\/p>\n<p># If you want to change the port on a SELinux system, you have to tell<br \/>\n# SELinux about this change.<br \/>\n# semanage port -a -t ssh_port_t -p tcp #PORTNUMBER<br \/>\n#<br \/>\nPort <strong>2244<\/strong><br \/>\n#AddressFamily any<br \/>\n#ListenAddress 0.0.0.0<br \/>\n#ListenAddress ::<\/p>\n<p>Save the file.<\/p>\n<p>After saving, don\u2019t exit until you\u2019ve completed these steps.<br \/>\n<!--more--><\/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<p><code>semanage port -a -t ssh_port_t -p tcp 2244<\/code><\/p>\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<p><code>yum -y install policycoreutils-python<\/code><\/p>\n<p>Then go and run the semange commend again to allow the new port through SELinux.<\/p>\n<p>After that, run the commands below to allow the new port through the firewall.<\/p>\n<p><code>firewall-cmd --permanent --zone=public --add-port=2244\/tcp<\/code><\/p>\n<p>Reload the firewall configurations<\/p>\n<p><code>firewall-cmd --reload<\/code><\/p>\n<p>Restart SSH by  running the commands below.<\/p>\n<p><code>systemctl restart sshd.service<\/code><\/p>\n<p>Verify that SSH is now running on the new port by running the commands below.<\/p>\n<p><code>ss -tnlp | grep ssh<\/code><\/p>\n<p>Exit and try signing in using the new port number.<\/p>\n<p><code>ssh root@192.168.0.1 -p 2244<\/code><\/p>\n<p>Enjoy!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>To change the default SSH port, the first thing you want to do is backup the current SSH configuration on your system. To do that, run the commands below. cp \/etc\/ssh\/sshd_config \/etc\/ssh\/sshd_config.bak Next, run the commands below to open the default SSH configuration file sudo vi \/etc\/ssh\/sshd_config # If you want to change the port\u2026 <span class=\"read-more\"><a href=\"https:\/\/www.whplus.com\/blog\/2018\/10\/22\/how-to-change-ssh-port-on-centos-7.html\">Read More &raquo;<\/a><\/span><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[],"class_list":["post-978","post","type-post","status-publish","format-standard","hentry","category-tutorial"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.whplus.com\/blog\/wp-json\/wp\/v2\/posts\/978","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.whplus.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.whplus.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.whplus.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.whplus.com\/blog\/wp-json\/wp\/v2\/comments?post=978"}],"version-history":[{"count":2,"href":"https:\/\/www.whplus.com\/blog\/wp-json\/wp\/v2\/posts\/978\/revisions"}],"predecessor-version":[{"id":980,"href":"https:\/\/www.whplus.com\/blog\/wp-json\/wp\/v2\/posts\/978\/revisions\/980"}],"wp:attachment":[{"href":"https:\/\/www.whplus.com\/blog\/wp-json\/wp\/v2\/media?parent=978"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.whplus.com\/blog\/wp-json\/wp\/v2\/categories?post=978"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.whplus.com\/blog\/wp-json\/wp\/v2\/tags?post=978"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}