Methods to modify the default SSH port in Linux

Publish: 2014-11-07 | Modify: 2014-11-07

Linux SSH default port is 22. For security reasons, it is necessary to modify the port to prevent malicious scanning by bots. Now, let's modify the port to 50000.

The method to modify the port is as follows:

  1. Open the file /etc/ssh/sshd_config using the command vi /etc/ssh/sshd_config.
  2. Find the line Port 22 and change it to Port 50000.
  3. Alternatively, you can use the command /usr/sbin/sshd -p 50000 to specify the port.

After making the changes, restart the sshd service using the command service sshd restart.

[root@localhost /]# vi /etc/ssh/sshd_config
Port 50000
[root@localhost /]# /usr/sbin/sshd -p 50000
[root@localhost /]# service sshd restart
Stopping sshd: [  OK  ]
Starting sshd: [  OK  ]

If you want to open both port 22 and 50000, you can add an additional line in /etc/ssh/sshd_config as follows:

[root@localhost /]# vi /etc/ssh/sshd_config
Port 22
Port 60000

Save the file and exit.


Comments