Pages
08-04-2026

Change default ssh port from 22 to 1234

Dmytro Tus
Full Stack Web developer

Normally we can login to the server using the command

ssh myuser@123.456.789.12

The default port in ssh is 22

Let's change it to 1234

Change port for ssh

Inside the folder

sudo nano /etc/ssh/sshd_config.d/change-port-ssh.conf

## content
Port 1234

Update sockets

sudo systemctl edit ssh.socket


/etc/systemd/system/ssh.socket.d/override.conf  ← your changes
/usr/lib/systemd/system/ssh.socket               ← untouched, safe to update


[Socket]
ListenStream=
ListenStream=*****:1234 <----- the same as in command below ( with status )
ListenStream=[::]:1234 <----- the same as in command below (with status )

Reload the ssh and socket

sudo systemctl daemon-reload
sudo systemctl restart ssh.socket ssh

 

Let's check if that changed properly

sudo ss -tlnp | grep ssh


##output
LISTEN 0      ****         *****:1234     
LISTEN 0      ****            [::]:1234 

Attention!!!

Don't logout until you are not sure that everything is working properly. In that case you can logout yourself and can not login to the sever with default port.

 

Login to the server using new port

Let's login

ssh myuser@123.456.789.1 -p 1234

When we need to update CI/CD workflows we need to 

ssh   → -p 1234  (lowercase)
scp   → -P 1234  (uppercase)
rsync → -e "ssh -p 1234"

Another posts