VIRTUAL SERVERS FOR BUSINESS

UA EN
0800 31 01 69 Free within Ukraine

Blog

How to change the default SSH port in Linux

12.12.2023 Reading ~5 min Author: Admin

This example is based on an Ubuntu distribution.

  1. Log into the system

    Log into the system with an account that has administrator privileges.

  2. Open the SSH configuration file

    Open the SSH configuration file using a text editor. This file is usually located at /etc/ssh/sshd_config. You can use nano, vi, or any other text editor of your choice.

    bash  
    
  • sudo nano /etc/ssh/sshd_config

  • Find the Port directive

    Find the line that starts with "Port". This specifies the port used for SSH. It is usually 22.

  • Port 22

  • Change the port

    Change the port value to the one you want to use. It is generally recommended to choose ports within the range of 1024-49151 that are not used by other services.

    For example:

  • Port 2222

  • Save and close the file

    Save the changes by pressing Ctrl + X, then Y, and then Enter (for the nano editor). If you are using a different text editor, follow its instructions for saving changes.

  • Restart the SSH service

    After making changes, restart the SSH service to apply the new settings.

    bash

sudo service ssh restart 

or

bash

  1. sudo systemctl restart ssh 
    

Now SSH will be listening on your new port. Remember the new port to be able to connect to the server. After changing the port, you will need to specify it explicitly when connecting:

bash  ssh -p 2222 user@your_ip_address

Do not forget to configure the appropriate firewall rules, if used, to allow access to the new port.

користувачів онлайн: