This article is for those who are concerned about their server’s security. You can try to change the SSH port as an additional layer to strengthen the security of your server. Therefore, changing the default SSH port (22) to something else will make it hard to guess for the hackers.

You need to follow a couple of simple steps to achieve this. The Linux distribution that you are using, Ubuntu or CentOS, won’t matter here.

Caution: before you proceed to change the SSH port, please read the following very carefully!

If you are using any firewall rules to allow specific IPs for port 22, make sure to update that with the new port prior to change the SSH port. AWS Security Group, Vultr Firewall, DigitalOcean Firewall they all allow custom rules. If you are not sure about it, try to take help from a system administrator. Otherwise, you may end up blocking yourself from logging into the server anymore. Similarly, if you are using any type of rsync between your server to/from another server, you have to include the new port there as well.

  1. Connect to your Linux server via SSH.
  2. If you are not logged in as a root user, make sure to use a sudo group user. Otherwise, you won’t be able to proceed with the next step.
  3. Run the following command: sudo vi /etc/ssh/sshd_config to edit the file.
  4. Within the file, locate the line where it says # Port 22.
  5. Remove the # at the beginning and consequently, change the port 22 to something else that you want, like 2222.
  6. Save the file and exit. If you are using Vim (vi command), then press Esc then :qw then press Enter. In the case of Nano, use Ctrl + X, then type Y, and then press Enter.
  7. Finally, restart the SSH service by running the command: sudo service sshd restart.

Now, you can connect to your server via SSH using the new port.

Published by Supratim Roy

I'm a technology enthusiast with over fifteen years of hands-on work experience in the IT industry. My specialization in web development technology, allows me to quickly adopt innovative approaches and leading-edge technology solutions.After passing the HS, I joined B.Com. under the CU. From the second year, I started studying computer courses. After graduating in the Computer Applications (BCA) from Indira Gandhi National Open University (IGNOU), I started my career as a Jr. Software Dev. in 2005. After four years, in 2009, I got the opportunity to pursue a master's degree. In 2011, I completed MCA from Sikkim Manipal University (SMU). I carried out the journey of my carrier as Sr. Software Dev., TL, and PM. Now I'm working as the VP of Technology at CodeClouds.I use my technical knowledge, skill, expertise, and previous experience to analyze the requirements of the clients and understand their business philosophy. I try to deliver quality solutions and products in a timely manner with a high percentage of accuracy. I also prepare and manage project specifications, scope documentation, workflow, data diagram, and development documentation. I lead a team of around 25-30 highly talented developers in a well-formed and structured way.I love listening to music and watching the action, adventure, thriller, horror movies, and Discovery, Animal Planet, and Nat Geo TV channels. Photography is also one of my hobbies, however, I'm really an amateur! I like to read technical articles, journals, and documentaries about Indian Himalayas and wildlife. I'm passionate about adventure sports. I encourage peoples to love adventure sports.I've traveled in many places and trekked in several parts of the Himalayas in India and Nepal. I'm a member of "MTG - Miles To Go" - a nature lover's association in Kolkata. I've done Rock Climbing course from Parvat Abhiyatri Sangha affiliated with Anandabazar Patrika. I also participate in several community initiatives taken by an NGO.

Leave a comment

Your email address will not be published. Required fields are marked *