{"id":23411,"date":"2021-06-04T11:40:51","date_gmt":"2021-06-04T11:40:51","guid":{"rendered":"https:\/\/linuxiac.com\/?p=23411"},"modified":"2022-04-02T22:47:10","modified_gmt":"2022-04-02T22:47:10","slug":"ssh-to-port-other-than-22","status":"publish","type":"post","link":"https:\/\/linuxiac.com\/ssh-to-port-other-than-22\/","title":{"rendered":"SSH to Port Other Than 22: How to Do It (with Examples)"},"content":{"rendered":"\n<p>By default, the SSH server runs on port 22. However, there are occasions when it is run in a different port.<\/p>\n\n\n\n<p>The&nbsp;<code>-p &lt;port&gt;<\/code>&nbsp;option can specify the port number to connect to when using the&nbsp;<code>ssh<\/code>&nbsp;command on Linux.<\/p>\n\n\n\n<p>For example, if you want to <a href=\"https:\/\/linuxiac.com\/how-to-use-ssh-tunneling\/\">access a remote server<\/a> that listens on port 2222, then just type:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-1\" data-shcb-language-name=\"CSS\" data-shcb-language-slug=\"css\"><span><code lang=\"bash\" class=\"hljs language-css language-bash\"><span class=\"hljs-selector-tag\">ssh<\/span> <span class=\"hljs-selector-tag\">-p<\/span> 2222 <span class=\"hljs-selector-tag\">user<\/span><span class=\"hljs-keyword\">@host<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-1\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">CSS<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">css<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<div style=\"height:15px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-how-to-change-the-ssh-server-port\">How to Change the SSH Server Port<\/h2>\n\n\n\n<p>Although having a strong and secure password is the only cybersecurity step most remote server users take, additional layers of security are always recommended.<\/p>\n\n\n\n<p>A simple but effective step you can take to enhance your server&#8217;s security is to change the port SSH uses to another than 22. However, you can set the server&#8217;s port number according to your requirements.<\/p>\n\n\n\n<p>To achieve it, follow these simple steps:<\/p>\n\n\n\n<p>Log in to the server as root and open the&nbsp;<code>\/etc\/ssh\/sshd_config<\/code>&nbsp;file with your preferred <a href=\"https:\/\/linuxiac.com\/differences-between-vi-and-vim-text-editors-explained\/\">text editor<\/a>. Locate the following line:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-2\" data-shcb-language-name=\"CSS\" data-shcb-language-slug=\"css\"><span><code lang=\"vim\" class=\"hljs language-css language-vim\"><span class=\"hljs-selector-id\">#Port<\/span> 22<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-2\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">CSS<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">css<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<div style=\"height:15px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>To use <code>ssh<\/code> to port other than 22 on your server, you need to change specific parameters within the <code>sshd_config<\/code> file.<\/p>\n\n\n\n<p>First, you need to uncomment the line by removing the number-sign (<code>#<\/code>) and changing&nbsp;<code>22<\/code>&nbsp;to the new port number that you want to use. Next, save the changes and then exit the text editor.<\/p>\n\n\n\n<p>That&#8217;s all. Now, restart the SSH service.<\/p>\n\n\n<pre class=\"wp-block-code\"><span><code lang=\"bash\" class=\"hljs language-bash\">systemctl restart sshd<\/code><\/span><\/pre>\n\n\n<div style=\"height:15px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>Changing the port will stop automatic attacks against your SSH server and make it more unlikely to be hit with a random scan. In other words, now it is more difficult to find your server, and you avoid being seen by random scans.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Conclusion<\/h2>\n\n\n\n<p>This guide showed you how to use the ssh command to <a href=\"https:\/\/linuxiac.com\/telnet-to-port\/\">connect to a port<\/a> other than the default 22.<\/p>\n\n\n\n<p>We have also discussed how to change the default SSH port on your Linux machine to safeguard your server.<\/p>\n\n\n\n<p>Remember to use the new private port range to keep your server stable and avoid disrupting running services.<\/p>\n\n\n\n<p>If you&#8217;re curious, <a href=\"https:\/\/www.ssh.com\/academy\/ssh\/port#the-story-of-getting-ssh-port-22\" target=\"_blank\" rel=\"noreferrer noopener\">here&nbsp;is the story<\/a> behind how the SSH port became 22.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This guide will explore how to change the SSH server port, and we will show you how to connect to a port other than the default 22.<\/p>\n","protected":false},"author":10,"featured_media":23417,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8,4417],"tags":[1484,3374,64],"class_list":["post-23411","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tips","category-linux-knowledge","tag-commands","tag-security","tag-ssh"],"blocksy_meta":{"styles_descriptor":{"styles":{"desktop":"","tablet":"","mobile":""},"google_fonts":[],"version":6},"post_title_panel":"","has_hero_section":"default","7f8731588623a4f4859e79656aab9fa5":"","hero_section":"type-2","hero_elements":[{"id":"custom_title","enabled":true,"heading_tag":"h1","title":"Home","__id":"kkVqcrPpXV2KLB98TlujZ"},{"id":"custom_description","enabled":false,"description_visibility":{"desktop":true,"tablet":true,"mobile":false},"__id":"Opj3lW4Es2pnz-6ipKt3f"},{"id":"custom_meta","enabled":true,"meta_elements":[{"id":"author","enabled":true,"label":"By","has_author_avatar":"yes","avatar_size":50,"__id":"o4ZO8D0n5k5b0WqqZNdNt"},{"id":"post_date","enabled":false,"label":"On","date_format_source":"default","date_format":"M j, Y","__id":"JfB-dIq5GggcWfx94axZu"},{"id":"updated_date","enabled":true,"label":"Updated","date_format_source":"default","date_format":"M j, Y","__id":"wDOVuFE-WrLjRU-qDzq3_"},{"id":"categories","enabled":false,"label":"In","style":"simple","__id":"ncIKQ_FsC3vEBhA-S8pMo"},{"id":"comments","enabled":true,"__id":"UWmgk-i9xz6nENIEnV5tb"}],"page_meta_elements":{"joined":true,"articles_count":true,"comments":true},"__id":"NDtBsq5F3E06m2Sg2Zysu","meta_type":"label","meta_divider":"circle"},{"id":"breadcrumbs","enabled":false,"__id":"Sv0jDYRF9sd8NavTiqY3S"}],"935169fd3e47dd816646fda108650af2":"","hero_alignment1":"CT_CSS_SKIP_RULE","hero_margin":40,"hero_alignment2":"center","hero_vertical_alignment":"center","5e82fab9f861636c1cd8e3d0f17c6335":"","hero_structure":"normal","8b87ef290c6f14e466a334c02588c739":"","page_title_bg_type":"custom_image","custom_hero_background":{"attachment_id":42591,"url":"https:\/\/linuxiac.com\/wp-content\/uploads\/2021\/06\/ssh-to-port-header-1024x237.png"},"parallax":{"desktop":false,"tablet":false,"mobile":false},"c0fa2ae1428825276f31181a60475dec":"","hero_height":"250px","pageTitleFont":{"family":"Default","variation":"Default","size":{"desktop":"3em","tablet":"3em","mobile":"3em","__changed":[]},"line-height":"CT_CSS_SKIP_RULE","letter-spacing":"CT_CSS_SKIP_RULE","text-transform":"CT_CSS_SKIP_RULE","text-decoration":"CT_CSS_SKIP_RULE"},"pageTitleFontColor":{"default":{"color":"CT_CSS_SKIP_RULEDEFAULT"}},"pageMetaFont":{"family":"Default","variation":"n6","size":"12px","line-height":"1.3","letter-spacing":"CT_CSS_SKIP_RULE","text-transform":"uppercase","text-decoration":"CT_CSS_SKIP_RULE"},"pageMetaFontColor":{"default":{"color":"CT_CSS_SKIP_RULEDEFAULT"},"hover":{"color":"CT_CSS_SKIP_RULEDEFAULT"}},"page_meta_button_type_font_colors":{"default":{"color":"CT_CSS_SKIP_RULEDEFAULT"},"hover":{"color":"CT_CSS_SKIP_RULEDEFAULT"}},"page_meta_button_type_background_colors":{"default":{"color":"CT_CSS_SKIP_RULEDEFAULT"},"hover":{"color":"CT_CSS_SKIP_RULEDEFAULT"}},"pageExcerptFont":{"family":"Default","variation":"Default","size":"CT_CSS_SKIP_RULE","line-height":"CT_CSS_SKIP_RULE","letter-spacing":"CT_CSS_SKIP_RULE","text-transform":"CT_CSS_SKIP_RULE","text-decoration":"CT_CSS_SKIP_RULE"},"pageExcerptColor":{"default":{"color":"CT_CSS_SKIP_RULEDEFAULT"}},"breadcrumbsFont":{"family":"Default","variation":"Default","size":"CT_CSS_SKIP_RULE","line-height":"CT_CSS_SKIP_RULE","letter-spacing":"CT_CSS_SKIP_RULE","text-transform":"CT_CSS_SKIP_RULE","text-decoration":"CT_CSS_SKIP_RULE"},"breadcrumbsFontColor":{"default":{"color":"CT_CSS_SKIP_RULEDEFAULT"},"initial":{"color":"CT_CSS_SKIP_RULEDEFAULT"},"hover":{"color":"CT_CSS_SKIP_RULEDEFAULT"}},"pageTitleOverlay":{"background_type":"color","background_pattern":"type-1","background_image":{"attachment_id":null,"x":0,"y":0},"gradient":"linear-gradient(135deg,rgba(6,147,227,1) 0%,rgb(155,81,224) 100%)","background_repeat":"repeat","background_size":"auto","background_attachment":"scroll","patternColor":{"default":{"color":"#e5e7ea"}},"overlayColor":{"default":{"color":"CT_CSS_SKIP_RULE"}},"backgroundColor":{"default":{"color":"CT_CSS_SKIP_RULE"}}},"pageTitleBackground":{"background_type":"color","background_pattern":"type-1","background_image":{"attachment_id":null,"x":0,"y":0},"gradient":"linear-gradient(135deg,rgba(6,147,227,1) 0%,rgb(155,81,224) 100%)","background_repeat":"repeat","background_size":"auto","background_attachment":"scroll","patternColor":{"default":{"color":"#e5e7ea"}},"overlayColor":{"default":{"color":"CT_CSS_SKIP_RULE"}},"backgroundColor":{"default":{"color":"var(--theme-palette-color-6)"}}},"pageTitlePadding":{"top":"50px","bottom":"50px","left":"auto","right":"auto","linked":true},"97f0f797a14dbacd6d71d0023869bb76":"","page_structure_type":"default","08ca8ef1a51e562d9605fc0b3634bed6":"","content_style_source":"inherit","content_style":"wide","5011166e2d01066b114ef6e331e3b4a9":"","vertical_spacing_source":"inherit","content_area_spacing":"both","background":{"background_type":"color","background_pattern":"type-1","background_image":{"attachment_id":null,"x":0,"y":0},"gradient":"linear-gradient(135deg,rgba(6,147,227,1) 0%,rgb(155,81,224) 100%)","background_repeat":"repeat","background_size":"auto","background_attachment":"scroll","patternColor":{"default":{"color":"#e5e7ea"}},"overlayColor":{"default":{"color":"CT_CSS_SKIP_RULE"}},"backgroundColor":{"default":{"color":"CT_CSS_SKIP_RULE"}}},"content_background":{"background_type":"color","background_pattern":"type-1","background_image":{"attachment_id":null,"x":0,"y":0},"gradient":"linear-gradient(135deg,rgba(6,147,227,1) 0%,rgb(155,81,224) 100%)","background_repeat":"repeat","background_size":"auto","background_attachment":"scroll","patternColor":{"default":{"color":"#e5e7ea"}},"overlayColor":{"default":{"color":"CT_CSS_SKIP_RULE"}},"backgroundColor":{"default":{"color":"var(--theme-palette-color-8)"}}},"content_boxed_shadow":{"inherit":false,"blur":18,"spread":-6,"v_offset":12,"h_offset":0,"inset":false,"enable":true,"color":{"color":"rgba(34, 56, 101, 0.04)"}},"boxed_content_spacing":{"desktop":{"top":"40px","bottom":"40px","left":"40px","right":"40px","linked":true},"tablet":{"top":"35px","bottom":"35px","left":"35px","right":"35px","linked":true},"mobile":{"top":"20px","bottom":"20px","left":"20px","right":"20px","linked":true}},"content_boxed_radius":{"top":"3px","bottom":"3px","left":"3px","right":"3px","linked":true},"bd13bacf70c715f37e69d92b96bfeb97":"","disable_featured_image":"no","disable_post_tags":"no","disable_share_box":"no","disable_author_box":"no","disable_posts_navigation":"no","disable_subscribe_form":"no","353376e5a45a1b8f4aa06cf1476b5ac7":"","disable_related_posts":"no","disable_header":"no","disable_footer":"no","c56069ab9d24d507583b25190f424141":"","header_footer_scripts_panel":"","header_scripts":"","b2d0b42632cdde307b62c4df2e97acca":"","header_after_body_scripts":"","ec9ac47fcf7894f6990610c081e86601":"","footer_scripts":"","8b64178298b8f05865e0c905b38ba311":"","e23d080f766d3ddfa23c592181bdda74":"","cc38155897bb30bc40f164879ed23c16":"","0fe3295faa42161ce1efb84c4f9232c8":"","61920b856210f8202b46da9b2866dd56":"","2641e733a3351cc24d8cbe82f725ac9d":"","559a4d630ffda31134db365591052b65":"","cd29f53e133c4b24ccb5aeb3fbc4c6fd":"","507109eba0b05adbac4db798c9a77fc2":"","0108f6bba9c5fce17b7bc4cf1a644489":"","8eb06700e6f2928d4351ee53b57532e8":"","c03494b9b8edacd7e0ea6d5273d98894":"","095f6d66fd23b6c51fdfe92427b79e3d":""},"_links":{"self":[{"href":"https:\/\/linuxiac.com\/wp-json\/wp\/v2\/posts\/23411","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/linuxiac.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/linuxiac.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/linuxiac.com\/wp-json\/wp\/v2\/users\/10"}],"replies":[{"embeddable":true,"href":"https:\/\/linuxiac.com\/wp-json\/wp\/v2\/comments?post=23411"}],"version-history":[{"count":0,"href":"https:\/\/linuxiac.com\/wp-json\/wp\/v2\/posts\/23411\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/linuxiac.com\/wp-json\/wp\/v2\/media\/23417"}],"wp:attachment":[{"href":"https:\/\/linuxiac.com\/wp-json\/wp\/v2\/media?parent=23411"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/linuxiac.com\/wp-json\/wp\/v2\/categories?post=23411"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/linuxiac.com\/wp-json\/wp\/v2\/tags?post=23411"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}