DEV Community

Ricardo
Ricardo

Posted on • Originally published at rmauro.dev on

Change Default Port 22 of SSH Server

Port 22 is used by default to establish an SSH connections. This port is automatically configured during the installation of your operating system.

To reduce the number of brute force attacks, you can change it to a different port for SSH access.

Changing the Default Port

To change the SSH port:

  • Log on to the server as an root or an administrator user.
  • Open the SSH configuration file sshd_config with the text editor nano :
$ nano /etc/ssh/sshd_config
Enter fullscreen mode Exit fullscreen mode
  • Search for the entry Port 22 (could be commented)
  • Replace it with the desired value - port between 1024 and 65536
  • Save and Restart the OpenSSH service
$ service ssh restart

# or 

$ systemctl restart sshd
Enter fullscreen mode Exit fullscreen mode

Top comments (4)

Collapse
 
ccoveille profile image
Christophe Colombier

I'm not sure about such approach than using fail2ban or things like that.

Changing the port address is an obfuscation technique

Collapse
 
rmaurodev profile image
Ricardo

Hi,

Check out this blog post

dev.to/rmaurodev/8-actions-for-har...

It has a more actions you can do.

Collapse
 
ccoveille profile image
Christophe Colombier

This second article is indeed what i would at least recommend

Collapse
 
rmaurodev profile image
Ricardo

I usually combine fail2band, different port number, do not allow password logins and dot not allow root user login.

This is just how to change the port number :)