{"id":5783,"date":"2024-01-19T12:04:26","date_gmt":"2024-01-19T12:04:26","guid":{"rendered":"https:\/\/natsav.com\/blog\/?p=5783"},"modified":"2024-01-25T11:21:59","modified_gmt":"2024-01-25T11:21:59","slug":"change-ssh-port-in-linux","status":"publish","type":"post","link":"https:\/\/natsav.com\/blog\/change-ssh-port-in-linux\/","title":{"rendered":"How to Change SSH  Port in Linux"},"content":{"rendered":"<p><span style=\"color: #000000;\">Changing your default port is one of the best ways to protect your SSH server. In this blog, we will explain how to Change SSH Port in Linux and walk you through changing it on your virtual private server <a href=\"https:\/\/natsav.com\/linux-vps-server-hosting.php\">(VPS)<\/a>.<br \/>\n<strong><span style=\"text-decoration: underline;\"><br \/>\nStep 1<\/span>:-<\/strong><\/span> <strong><span style=\"text-decoration: underline; color: #000000;\">Login to Your Server<\/span>.<br \/>\n<\/strong><span style=\"color: #333333;\">Connect to your <a href=\"https:\/\/natsav.com\/linux-vps-server-hosting.php\">Linux VPS<\/a> server using your current SSH port. Open a terminal and use the following command, replacing &#8216;username&#8217; and &#8216;your-server-ip&#8217; with your actual username and server IP address.<\/span><br \/>\n<span style=\"color: #333333;\"># [ ssh username@your-server-ip ]<\/span><\/p>\n<p><strong><span style=\"color: #000000;\"><span style=\"text-decoration: underline;\">Step 2<\/span>:-<\/span> <span style=\"text-decoration: underline;\"><span style=\"color: #000000; text-decoration: underline;\">Edit the SSH Configuration File<\/span><\/span>.<br \/>\n<\/strong><span style=\"color: #333333;\">Once logged in, edit the SSH daemon configuration file. The location of this file can vary, but it is commonly found at &#8216;\/etc\/ssh\/sshd_config&#8217;. You can use a text editor like &#8216;nano&#8217; or &#8216;vi.&#8217;<\/span><br \/>\n<span style=\"color: #333333;\"># [ sudo nano \/etc\/ssh\/sshd_config ]<\/span><\/p>\n<p><strong><span style=\"text-decoration: underline; color: #000000;\">Step 3<\/span>:-<span style=\"text-decoration: underline; color: #000000;\"> Locate the Port Setting<\/span>.<br \/>\n<\/strong><span style=\"color: #333333;\">Look for the line in the configuration file that specifies the port. It will look something like this.<\/span><br \/>\n<span style=\"color: #333333;\"># [ #Port 22 ]<\/span><br \/>\n<span style=\"color: #333333;\">Uncomment the line (remove the # at the beginning) and change the port number. For example:<\/span><br \/>\n<span style=\"color: #333333;\"># [ Port 2222 ]<\/span><\/p>\n<p><span style=\"text-decoration: underline;\"><span style=\"color: #000000; text-decoration: underline;\"><strong>Step 4<\/strong><\/span><\/span><strong><span style=\"color: #000000;\">:-<span style=\"text-decoration: underline;\">Save and Close the File<\/span>.<\/span><br \/>\n<\/strong><span style=\"color: #333333;\">Save your changes and exit the text editor.<\/span><\/p>\n<p><strong><span style=\"color: #000000;\"><span style=\"text-decoration: underline;\">Step 5<\/span>:- <span style=\"text-decoration: underline;\">Restart the SSH Service<\/span><\/span>.<br \/>\n<\/strong><span style=\"color: #333333;\">To apply the changes, restart the SSH service. The command can vary depending on your Linux distribution. Common commands include:<\/span><br \/>\n<span style=\"color: #333333;\">For systems that use &#8216;systemd&#8217; (e.g., Ubuntu 16.04 and later, CentOS 7 and later):<\/span><br \/>\n<span style=\"color: #333333;\"># [ sudo systemctl restart ssh ]<\/span><br \/>\n<span style=\"color: #333333;\">For systems using &#8216;service&#8217; (older systems):<\/span><br \/>\n<span style=\"color: #333333;\"># [ sudo service ssh restart ]<\/span><\/p>\n<p><strong><span style=\"color: #000000;\">Step 6:-<\/span><\/strong> <strong><span style=\"text-decoration: underline;\"><span style=\"color: #000000; text-decoration: underline;\">Verify the New Port<\/span><\/span>.<br \/>\n<\/strong><span style=\"color: #333333;\">Before closing your current SSH session, open a new terminal window and attempt to reconnect using the new port.<\/span><strong><br \/>\n<\/strong><span style=\"color: #333333;\"># [ ssh -p 2222 username@your-server-ip ]<\/span><br \/>\n<span style=\"color: #333333;\">Replace &#8216;2222&#8217; with the new port number.<\/span><\/p>\n<p><span style=\"color: #000000;\"><strong><span style=\"text-decoration: underline;\">Step 7<\/span>:-<\/strong><\/span> <strong><span style=\"text-decoration: underline; color: #000000;\">Update Firewall Rules<\/span>.<br \/>\n<\/strong><span style=\"color: #333333;\">Start by making sure the newly selected port is not blocked. If this is a new\u00a0<a href=\"https:\/\/natsav.com\/linux-vps-server-hosting.php\" rel=\"follow\" data-wpel-link=\"internal\">VPS setup<\/a>, all ports should be open by default. For example, using &#8216;ufw&#8217; on Ubuntu.<\/span><br \/>\n<span style=\"color: #333333;\"># [ sudo ufw allow 2222 ]<\/span><br \/>\n<span style=\"color: #333333;\"># [ sudo ufw reload ]<\/span><\/p>\n<p><span style=\"color: #000000;\"><strong><span style=\"text-decoration: underline;\">Step 8<\/span>:-<\/strong><\/span> <strong><span style=\"text-decoration: underline;\"><span style=\"color: #000000; text-decoration: underline;\">Disconnect and Reconnect<\/span><\/span>.<br \/>\n<\/strong><span style=\"color: #333333;\">If everything is working correctly, you can now disconnect from the old SSH session and reconnect using the new port.<\/span><\/p>\n<p><strong><span style=\"text-decoration: underline;\"><span style=\"color: #000000; text-decoration: underline;\">Note<\/span><\/span>:-<\/strong> <span style=\"color: #333333;\">Remember that changing the default SSH port alone is not a foolproof security measure. Ensure that you have strong authentication methods in place, such as key-based authentication, and consider implementing additional security measures to protect your server.<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Changing your default port is one of the best ways to protect your SSH server. In this blog, we will explain how to Change SSH Port in Linux and walk you through changing it on your virtual private server (VPS). Step 1:- Login to Your Server. Connect to your Linux VPS server using your current [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":5789,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[254],"tags":[],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"https:\/\/i0.wp.com\/natsav.com\/blog\/wp-content\/uploads\/2024\/01\/SSH-e1705665938476.png?fit=657%2C416&ssl=1","jetpack-related-posts":[],"_links":{"self":[{"href":"https:\/\/natsav.com\/blog\/wp-json\/wp\/v2\/posts\/5783"}],"collection":[{"href":"https:\/\/natsav.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/natsav.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/natsav.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/natsav.com\/blog\/wp-json\/wp\/v2\/comments?post=5783"}],"version-history":[{"count":6,"href":"https:\/\/natsav.com\/blog\/wp-json\/wp\/v2\/posts\/5783\/revisions"}],"predecessor-version":[{"id":5800,"href":"https:\/\/natsav.com\/blog\/wp-json\/wp\/v2\/posts\/5783\/revisions\/5800"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/natsav.com\/blog\/wp-json\/wp\/v2\/media\/5789"}],"wp:attachment":[{"href":"https:\/\/natsav.com\/blog\/wp-json\/wp\/v2\/media?parent=5783"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/natsav.com\/blog\/wp-json\/wp\/v2\/categories?post=5783"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/natsav.com\/blog\/wp-json\/wp\/v2\/tags?post=5783"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}