{"id":14656,"date":"2024-10-08T08:23:57","date_gmt":"2024-10-08T08:23:57","guid":{"rendered":"https:\/\/truehost.com\/support\/?post_type=docs&#038;p=14656"},"modified":"2024-10-09T04:16:47","modified_gmt":"2024-10-09T04:16:47","password":"","slug":"how-to-change-ssh-port-to-a-custom-port","status":"publish","type":"docs","link":"https:\/\/truehost.com\/support\/knowledge-base\/how-to-change-ssh-port-to-a-custom-port\/","title":{"rendered":"How to change SSH port to a custom port"},"content":{"rendered":"\n<p>Changing the default SSH port (22) to a custom port (like 1026)  is a common security practice that helps reduce unauthorized login attempts. Below is a step-by-step guide to change the SSH port on your server.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Prerequisites<\/h2>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Root or sudo user access<\/strong> to the server.<\/li>\n\n\n\n<li><strong>SSH client<\/strong>: You should have SSH access to your server to make the necessary configuration changes.<\/li>\n\n\n\n<li><strong>Firewall access<\/strong>: Ensure that your firewall (if any) is open for the new SSH port before changing it.<\/li>\n<\/ol>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Step-by-Step Guide to Changing the SSH Port<\/strong><\/h2>\n\n\n\n<p>Follow these steps<\/p>\n\n\n\n<h5 class=\"wp-block-heading\"><strong>Step 1: Choose a New SSH Port<\/strong><\/h5>\n\n\n\n<p>Select an available port number that is not already in use by other services on your server. It\u2019s recommended to use a port number higher than 1024, as ports below this range are reserved for specific services<\/p>\n\n\n\n<h5 class=\"wp-block-heading\"><strong>Step 2: Update the SSH Configuration File<\/strong><\/h5>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Access your server via SSH<\/strong> using the current port (default is 22). See <strong><a href=\"https:\/\/truehost.com\/support\/knowledge-base\/how-to-access-a-server-via-ssh-terminal\/\" target=\"_blank\" rel=\"noreferrer noopener\">this<\/a><\/strong><\/li>\n<\/ul>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Open the SSH configuration file<\/strong> (<code>sshd_config<\/code>) for editing, using your preferred text editor<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>sudo vi \/etc\/ssh\/sshd_config<\/strong> or <strong>sudo nano \/etc\/ssh\/sshd_config<\/strong><\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Find the line<\/strong> that specifies the port (usually commented out):<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>Port 22<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full is-style-zoooom\"><img loading=\"lazy\" decoding=\"async\" width=\"787\" height=\"157\" src=\"https:\/\/truehost.com\/support\/wp-content\/uploads\/2024\/10\/image-203.png\" alt=\"\" class=\"wp-image-14776\" srcset=\"https:\/\/truehost.com\/support\/wp-content\/uploads\/2024\/10\/image-203.png 787w, https:\/\/truehost.com\/support\/wp-content\/uploads\/2024\/10\/image-203-300x60.png 300w, https:\/\/truehost.com\/support\/wp-content\/uploads\/2024\/10\/image-203-768x153.png 768w\" sizes=\"auto, (max-width: 787px) 100vw, 787px\" \/><\/figure>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Uncomment the line<\/strong> (remove the <code>#<\/code>) and change the value to your custom port number:<\/li>\n<\/ul>\n\n\n\n<figure class=\"wp-block-image size-full is-style-zoooom\"><img loading=\"lazy\" decoding=\"async\" width=\"670\" height=\"172\" src=\"https:\/\/truehost.com\/support\/wp-content\/uploads\/2024\/10\/image-204.png\" alt=\"\" class=\"wp-image-14777\" srcset=\"https:\/\/truehost.com\/support\/wp-content\/uploads\/2024\/10\/image-204.png 670w, https:\/\/truehost.com\/support\/wp-content\/uploads\/2024\/10\/image-204-300x77.png 300w\" sizes=\"auto, (max-width: 670px) 100vw, 670px\" \/><\/figure>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Save the file<\/strong> and exit the text editor (if using <code>vim<\/code>, press <code>ESC <\/code>, then <strong>wq<\/strong>, then <code>Enter<\/code>).<\/li>\n<\/ul>\n\n\n\n<h5 class=\"wp-block-heading\"><strong>Step 3: Adjust Firewall Settings<\/strong><\/h5>\n\n\n\n<p>If you are using a firewall (e.g., <code>firewalld<\/code>, <code>iptables<\/code>, or <code>ufw<\/code>), you must allow traffic on the new SSH port.<\/p>\n\n\n\n<p>If you do not have your firewall on, you may either turn it on then allow the port or just leave it like that since the firewall is off.<\/p>\n\n\n\n<p><strong>For Firewalld (Centos, Almalinux, RedHart):<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Add the new SSH port (e.g., <code>1026<\/code>):<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>sudo firewall-cmd --permanent --add-port1026\/tcp<\/strong><\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Reload the firewall:<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>sudo firewall-cmd --reload<\/strong><\/code><\/pre>\n\n\n\n<p><strong>For UFW (Ubuntu systems):<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Allow the new SSH port:<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>sudo ufw allow 1026\/tcp<\/strong><\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Reload the firewall:<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>sudo ufw reload<\/strong><\/code><\/pre>\n\n\n\n<p><strong>For Iptables:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Add the new SSH port to iptables:<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>sudo iptables -A INPUT -p tcp --dport 2222 -j ACCEPT<\/strong><\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Save the iptables rules (on CentOS, use <code>service iptables save<\/code>).<\/li>\n<\/ul>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"471\" height=\"119\" src=\"https:\/\/truehost.com\/support\/wp-content\/uploads\/2024\/10\/image-205.png\" alt=\"\" class=\"wp-image-14778\" srcset=\"https:\/\/truehost.com\/support\/wp-content\/uploads\/2024\/10\/image-205.png 471w, https:\/\/truehost.com\/support\/wp-content\/uploads\/2024\/10\/image-205-300x76.png 300w\" sizes=\"auto, (max-width: 471px) 100vw, 471px\" \/><\/figure>\n\n\n\n<h5 class=\"wp-block-heading\"><strong>Step 4: Restart the SSH Service<\/strong><\/h5>\n\n\n\n<ul class=\"wp-block-list\">\n<li>After making changes to the SSH configuration, you must restart the SSH service for the changes to take effect.<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>sudo systemctl restart sshd<\/strong><\/code><\/pre>\n\n\n\n<h5 class=\"wp-block-heading\"><strong>Step 5: Test the New SSH Port<\/strong><\/h5>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Before closing your current SSH session, <strong>test the new port<\/strong> to ensure you can still access the server.<\/li>\n\n\n\n<li>Replace <code>1026<\/code> with the port number you chose and <code>server_ip<\/code> with your server\u2019s IP address.<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>ssh -p 1026 root@server_ip<\/strong><\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>If the connection works, your port change is successful.<\/li>\n<\/ul>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"357\" height=\"77\" src=\"https:\/\/truehost.com\/support\/wp-content\/uploads\/2024\/10\/image-206.png\" alt=\"\" class=\"wp-image-14784\" srcset=\"https:\/\/truehost.com\/support\/wp-content\/uploads\/2024\/10\/image-206.png 357w, https:\/\/truehost.com\/support\/wp-content\/uploads\/2024\/10\/image-206-300x65.png 300w\" sizes=\"auto, (max-width: 357px) 100vw, 357px\" \/><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>Changing the default SSH port (22) to a custom port (like 1026) is a common security practice that helps reduce unauthorized login attempts. Below is a step-by-step guide to change the SSH port on your server. Prerequisites Step-by-Step Guide to Changing the SSH Port Follow these steps Step 1: Choose a New SSH Port Select [&hellip;]<\/p>\n","protected":false},"author":9,"featured_media":0,"comment_status":"open","ping_status":"closed","template":"","meta":{"_eb_attr":"","_exactmetrics_skip_tracking":false,"_exactmetrics_sitenote_active":false,"_exactmetrics_sitenote_note":"","_exactmetrics_sitenote_category":0,"footnotes":""},"doc_category":[1820,1824,1879,2128],"doc_tag":[],"class_list":["post-14656","docs","type-docs","status-publish","hentry","doc_category-cloud-servers-in-kenya","doc_category-dedicated-servers","doc_category-servers","doc_category-vps-servers"],"year_month":"2026-06","word_count":424,"total_views":0,"reactions":{"happy":0,"normal":0,"sad":0},"author_info":{"name":"Eugene","author_nicename":"eugene","author_url":"https:\/\/truehost.com\/support\/author\/eugene\/"},"doc_category_info":[{"term_name":"Cloud servers in Kenya","term_url":"https:\/\/truehost.com\/support\/docs-category\/cloud-servers-in-kenya\/"},{"term_name":"dedicated servers","term_url":"https:\/\/truehost.com\/support\/docs-category\/dedicated-servers\/"},{"term_name":"Servers","term_url":"https:\/\/truehost.com\/support\/docs-category\/servers\/"},{"term_name":"VPS-Servers","term_url":"https:\/\/truehost.com\/support\/docs-category\/vps-servers\/"}],"doc_tag_info":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.8 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>How to change SSH port to a custom port -<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.truehost.com\/support\/knowledge-base\/how-to-change-ssh-port-to-a-custom-port\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to change SSH port to a custom port -\" \/>\n<meta property=\"og:description\" content=\"Changing the default SSH port (22) to a custom port (like 1026) is a common security practice that helps reduce unauthorized login attempts. Below is a step-by-step guide to change the SSH port on your server. Prerequisites Step-by-Step Guide to Changing the SSH Port Follow these steps Step 1: Choose a New SSH Port Select [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.truehost.com\/support\/knowledge-base\/how-to-change-ssh-port-to-a-custom-port\/\" \/>\n<meta property=\"article:modified_time\" content=\"2024-10-09T04:16:47+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/truehost.com\/support\/wp-content\/uploads\/2024\/10\/image-203.png\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.truehost.com\\\/support\\\/knowledge-base\\\/how-to-change-ssh-port-to-a-custom-port\\\/\",\"url\":\"https:\\\/\\\/www.truehost.com\\\/support\\\/knowledge-base\\\/how-to-change-ssh-port-to-a-custom-port\\\/\",\"name\":\"How to change SSH port to a custom port -\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.truehost.com\\\/support\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.truehost.com\\\/support\\\/knowledge-base\\\/how-to-change-ssh-port-to-a-custom-port\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.truehost.com\\\/support\\\/knowledge-base\\\/how-to-change-ssh-port-to-a-custom-port\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/truehost.com\\\/support\\\/wp-content\\\/uploads\\\/2024\\\/10\\\/image-203.png\",\"datePublished\":\"2024-10-08T08:23:57+00:00\",\"dateModified\":\"2024-10-09T04:16:47+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.truehost.com\\\/support\\\/knowledge-base\\\/how-to-change-ssh-port-to-a-custom-port\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.truehost.com\\\/support\\\/knowledge-base\\\/how-to-change-ssh-port-to-a-custom-port\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.truehost.com\\\/support\\\/knowledge-base\\\/how-to-change-ssh-port-to-a-custom-port\\\/#primaryimage\",\"url\":\"https:\\\/\\\/truehost.com\\\/support\\\/wp-content\\\/uploads\\\/2024\\\/10\\\/image-203.png\",\"contentUrl\":\"https:\\\/\\\/truehost.com\\\/support\\\/wp-content\\\/uploads\\\/2024\\\/10\\\/image-203.png\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.truehost.com\\\/support\\\/knowledge-base\\\/how-to-change-ssh-port-to-a-custom-port\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.truehost.com\\\/support\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to change SSH port to a custom port\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.truehost.com\\\/support\\\/#website\",\"url\":\"https:\\\/\\\/www.truehost.com\\\/support\\\/\",\"name\":\"\",\"description\":\"Help In a Click\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.truehost.com\\\/support\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.truehost.com\\\/support\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.truehost.com\\\/support\\\/#organization\",\"name\":\"Truehost Kenya\",\"url\":\"https:\\\/\\\/www.truehost.com\\\/support\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.truehost.com\\\/support\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/truehost.com\\\/support\\\/wp-content\\\/uploads\\\/2026\\\/04\\\/cropped-image_2026-04-16_174808866.png\",\"contentUrl\":\"https:\\\/\\\/truehost.com\\\/support\\\/wp-content\\\/uploads\\\/2026\\\/04\\\/cropped-image_2026-04-16_174808866.png\",\"width\":240,\"height\":48,\"caption\":\"Truehost Kenya\"},\"image\":{\"@id\":\"https:\\\/\\\/www.truehost.com\\\/support\\\/#\\\/schema\\\/logo\\\/image\\\/\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to change SSH port to a custom port -","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.truehost.com\/support\/knowledge-base\/how-to-change-ssh-port-to-a-custom-port\/","og_locale":"en_US","og_type":"article","og_title":"How to change SSH port to a custom port -","og_description":"Changing the default SSH port (22) to a custom port (like 1026) is a common security practice that helps reduce unauthorized login attempts. Below is a step-by-step guide to change the SSH port on your server. Prerequisites Step-by-Step Guide to Changing the SSH Port Follow these steps Step 1: Choose a New SSH Port Select [&hellip;]","og_url":"https:\/\/www.truehost.com\/support\/knowledge-base\/how-to-change-ssh-port-to-a-custom-port\/","article_modified_time":"2024-10-09T04:16:47+00:00","og_image":[{"url":"https:\/\/truehost.com\/support\/wp-content\/uploads\/2024\/10\/image-203.png","type":"","width":"","height":""}],"twitter_card":"summary_large_image","twitter_misc":{"Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.truehost.com\/support\/knowledge-base\/how-to-change-ssh-port-to-a-custom-port\/","url":"https:\/\/www.truehost.com\/support\/knowledge-base\/how-to-change-ssh-port-to-a-custom-port\/","name":"How to change SSH port to a custom port -","isPartOf":{"@id":"https:\/\/www.truehost.com\/support\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.truehost.com\/support\/knowledge-base\/how-to-change-ssh-port-to-a-custom-port\/#primaryimage"},"image":{"@id":"https:\/\/www.truehost.com\/support\/knowledge-base\/how-to-change-ssh-port-to-a-custom-port\/#primaryimage"},"thumbnailUrl":"https:\/\/truehost.com\/support\/wp-content\/uploads\/2024\/10\/image-203.png","datePublished":"2024-10-08T08:23:57+00:00","dateModified":"2024-10-09T04:16:47+00:00","breadcrumb":{"@id":"https:\/\/www.truehost.com\/support\/knowledge-base\/how-to-change-ssh-port-to-a-custom-port\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.truehost.com\/support\/knowledge-base\/how-to-change-ssh-port-to-a-custom-port\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.truehost.com\/support\/knowledge-base\/how-to-change-ssh-port-to-a-custom-port\/#primaryimage","url":"https:\/\/truehost.com\/support\/wp-content\/uploads\/2024\/10\/image-203.png","contentUrl":"https:\/\/truehost.com\/support\/wp-content\/uploads\/2024\/10\/image-203.png"},{"@type":"BreadcrumbList","@id":"https:\/\/www.truehost.com\/support\/knowledge-base\/how-to-change-ssh-port-to-a-custom-port\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.truehost.com\/support\/"},{"@type":"ListItem","position":2,"name":"How to change SSH port to a custom port"}]},{"@type":"WebSite","@id":"https:\/\/www.truehost.com\/support\/#website","url":"https:\/\/www.truehost.com\/support\/","name":"","description":"Help In a Click","publisher":{"@id":"https:\/\/www.truehost.com\/support\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.truehost.com\/support\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.truehost.com\/support\/#organization","name":"Truehost Kenya","url":"https:\/\/www.truehost.com\/support\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.truehost.com\/support\/#\/schema\/logo\/image\/","url":"https:\/\/truehost.com\/support\/wp-content\/uploads\/2026\/04\/cropped-image_2026-04-16_174808866.png","contentUrl":"https:\/\/truehost.com\/support\/wp-content\/uploads\/2026\/04\/cropped-image_2026-04-16_174808866.png","width":240,"height":48,"caption":"Truehost Kenya"},"image":{"@id":"https:\/\/www.truehost.com\/support\/#\/schema\/logo\/image\/"}}]}},"_links":{"self":[{"href":"https:\/\/truehost.com\/support\/wp-json\/wp\/v2\/docs\/14656","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/truehost.com\/support\/wp-json\/wp\/v2\/docs"}],"about":[{"href":"https:\/\/truehost.com\/support\/wp-json\/wp\/v2\/types\/docs"}],"author":[{"embeddable":true,"href":"https:\/\/truehost.com\/support\/wp-json\/wp\/v2\/users\/9"}],"replies":[{"embeddable":true,"href":"https:\/\/truehost.com\/support\/wp-json\/wp\/v2\/comments?post=14656"}],"version-history":[{"count":7,"href":"https:\/\/truehost.com\/support\/wp-json\/wp\/v2\/docs\/14656\/revisions"}],"predecessor-version":[{"id":14786,"href":"https:\/\/truehost.com\/support\/wp-json\/wp\/v2\/docs\/14656\/revisions\/14786"}],"wp:attachment":[{"href":"https:\/\/truehost.com\/support\/wp-json\/wp\/v2\/media?parent=14656"}],"wp:term":[{"taxonomy":"doc_category","embeddable":true,"href":"https:\/\/truehost.com\/support\/wp-json\/wp\/v2\/doc_category?post=14656"},{"taxonomy":"doc_tag","embeddable":true,"href":"https:\/\/truehost.com\/support\/wp-json\/wp\/v2\/doc_tag?post=14656"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}