{"id":20,"date":"2021-06-28T11:35:23","date_gmt":"2021-06-28T11:35:23","guid":{"rendered":"http:\/\/host2day.in\/blog\/?page_id=20"},"modified":"2021-10-28T06:59:45","modified_gmt":"2021-10-28T06:59:45","slug":"change-ssh-port-in-centos","status":"publish","type":"post","link":"https:\/\/host2day.in\/blog\/change-ssh-port-in-centos\/","title":{"rendered":"How to? Change SSH port in CentOS&#8230;"},"content":{"rendered":"\n<p>The default port to access using SSH is port 22. This default port can be changed in Linux to any custom port not used by other applications.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>vim \/etc\/ssh\/sshd_config\n<\/code><\/pre>\n\n\n\n<p>Open SSH configuration file using the above command and locate the line where port is updated as #Port 22<\/p>\n\n\n\n<div class=\"wp-block-group\"><div class=\"wp-block-group__inner-container is-layout-flow wp-block-group-is-layout-flow\">\n<figure class=\"wp-block-gallery aligncenter columns-1 is-cropped wp-block-gallery-1 is-layout-flex wp-block-gallery-is-layout-flex\"><ul class=\"blocks-gallery-grid\"><li class=\"blocks-gallery-item\"><figure><img loading=\"lazy\" decoding=\"async\" width=\"392\" height=\"21\" src=\"http:\/\/host2day.in\/blog\/wp-content\/uploads\/2021\/06\/port22.png\" alt=\"\" data-id=\"22\" data-full-url=\"http:\/\/host2day.in\/blog\/wp-content\/uploads\/2021\/06\/port22.png\" data-link=\"http:\/\/host2day.in\/blog\/?attachment_id=22\" class=\"wp-image-22\" srcset=\"https:\/\/host2day.in\/blog\/wp-content\/uploads\/2021\/06\/port22.png 392w, https:\/\/host2day.in\/blog\/wp-content\/uploads\/2021\/06\/port22-300x16.png 300w\" sizes=\"auto, (max-width: 392px) 100vw, 392px\" \/><\/figure><\/li><\/ul><\/figure>\n<\/div><\/div>\n\n\n\n<p>Uncomment the line by removing &#8220;#&#8221; from the beginning and update the customer port value here, I have updated my custom port as 2244&#8230;<\/p>\n\n\n\n<div class=\"wp-block-group\"><div class=\"wp-block-group__inner-container is-layout-flow wp-block-group-is-layout-flow\">\n<figure class=\"wp-block-gallery aligncenter columns-1 is-cropped wp-block-gallery-2 is-layout-flex wp-block-gallery-is-layout-flex\"><ul class=\"blocks-gallery-grid\"><li class=\"blocks-gallery-item\"><figure><img loading=\"lazy\" decoding=\"async\" width=\"325\" height=\"19\" src=\"http:\/\/host2day.in\/blog\/wp-content\/uploads\/2021\/06\/port2244.png\" alt=\"\" data-id=\"25\" data-full-url=\"http:\/\/host2day.in\/blog\/wp-content\/uploads\/2021\/06\/port2244.png\" data-link=\"http:\/\/host2day.in\/blog\/?attachment_id=25\" class=\"wp-image-25\" srcset=\"https:\/\/host2day.in\/blog\/wp-content\/uploads\/2021\/06\/port2244.png 325w, https:\/\/host2day.in\/blog\/wp-content\/uploads\/2021\/06\/port2244-300x18.png 300w\" sizes=\"auto, (max-width: 325px) 100vw, 325px\" \/><\/figure><\/li><\/ul><\/figure>\n<\/div><\/div>\n\n\n\n<p>Press &#8220;Esc&#8221; then enter &#8220;:qw&#8221; to save your changes and close file<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Allow new SSH port on SELinux<\/h2>\n\n\n\n<p>The default port allowed for SSH port is 22, Since, We have recently updated the port to 2244, the same need to be updated here as well.<\/p>\n\n\n\n<p>To allow sshd bind to new updated port, we need to modify the port type here <strong>ssh_port_t<\/strong>.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>semanage port -l | grep ssh\nssh_port_t                     tcp      22<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>semanage port -a -t ssh_port_t -p tcp 2244<\/code><\/pre>\n\n\n\n<p>Once the port has been modified confirm if the port has been allowed successfully for ssh.<\/p>\n\n\n\n<figure class=\"wp-block-gallery aligncenter columns-1 is-cropped wp-block-gallery-3 is-layout-flex wp-block-gallery-is-layout-flex\"><ul class=\"blocks-gallery-grid\"><li class=\"blocks-gallery-item\"><figure><img loading=\"lazy\" decoding=\"async\" width=\"400\" height=\"40\" src=\"http:\/\/host2day.in\/blog\/wp-content\/uploads\/2021\/06\/updated-port.png\" alt=\"\" data-id=\"30\" data-full-url=\"http:\/\/host2day.in\/blog\/wp-content\/uploads\/2021\/06\/updated-port.png\" data-link=\"http:\/\/host2day.in\/blog\/?attachment_id=30\" class=\"wp-image-30\" srcset=\"https:\/\/host2day.in\/blog\/wp-content\/uploads\/2021\/06\/updated-port.png 400w, https:\/\/host2day.in\/blog\/wp-content\/uploads\/2021\/06\/updated-port-300x30.png 300w\" sizes=\"auto, (max-width: 400px) 100vw, 400px\" \/><\/figure><\/li><\/ul><\/figure>\n\n\n\n<div class=\"wp-block-buttons is-layout-flex wp-block-buttons-is-layout-flex\">\n<div class=\"wp-block-button\"><a class=\"wp-block-button__link\" href=\"http:\/\/host2day.in\/blog\/?p=68\" target=\"_blank\" rel=\"noreferrer noopener\">HOW TO ENABLE SELINUX<\/a><\/div>\n<\/div>\n\n\n\n<h2 class=\"wp-block-heading\">Enable SSH port on Firewall<\/h2>\n\n\n\n<p>Once port is configured in sshd, its time to allow the custom port in firewall.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>firewall-cmd --add-port=2244\/tcp --permanent\nfirewall-cmd --reload<\/code><\/pre>\n\n\n\n<div class=\"wp-block-buttons is-layout-flex wp-block-buttons-is-layout-flex\">\n<div class=\"wp-block-button\"><a class=\"wp-block-button__link\" href=\"http:\/\/host2day.in\/blog\/?p=19\" target=\"_blank\" rel=\"http:\/\/host2day.in\/blog\/?p=19 noopener\">HOW TO INSTALL FIREWALLD<\/a><\/div>\n<\/div>\n\n\n\n<h2 class=\"wp-block-heading\">Restart SSHD service<\/h2>\n\n\n\n<p>Now, for the final step, restart ssh service for the changes to take place<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>systemctl restart sshd<\/code><\/pre>\n\n\n\n<p>The PORT is successfully changed to custom port&#8230;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The default port to access using SSH is port 22. This default port can be changed in Linux to any custom port not used by other applications. Open SSH configuration file using the above command and locate the line where port is updated as #Port 22 Uncomment the line by removing &#8220;#&#8221; from the beginning&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_kad_post_transparent":"","_kad_post_title":"","_kad_post_layout":"","_kad_post_sidebar_id":"","_kad_post_content_style":"","_kad_post_vertical_padding":"","_kad_post_feature":"","_kad_post_feature_position":"","_kad_post_header":false,"_kad_post_footer":false,"footnotes":""},"categories":[4,9],"tags":[],"class_list":["post-20","post","type-post","status-publish","format-standard","hentry","category-cent-os","category-linux"],"_links":{"self":[{"href":"https:\/\/host2day.in\/blog\/wp-json\/wp\/v2\/posts\/20","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/host2day.in\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/host2day.in\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/host2day.in\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/host2day.in\/blog\/wp-json\/wp\/v2\/comments?post=20"}],"version-history":[{"count":28,"href":"https:\/\/host2day.in\/blog\/wp-json\/wp\/v2\/posts\/20\/revisions"}],"predecessor-version":[{"id":110,"href":"https:\/\/host2day.in\/blog\/wp-json\/wp\/v2\/posts\/20\/revisions\/110"}],"wp:attachment":[{"href":"https:\/\/host2day.in\/blog\/wp-json\/wp\/v2\/media?parent=20"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/host2day.in\/blog\/wp-json\/wp\/v2\/categories?post=20"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/host2day.in\/blog\/wp-json\/wp\/v2\/tags?post=20"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}