SSH uses port 22 by default. If your server listens on a different port, pass it with -p when connecting. Watch out: for scp the flag is -P, with a capital P.

ssh -p 2222 root@203.0.113.10
scp -P 2222 file.txt root@203.0.113.10:/root/
rsync -e "ssh -p 2222" -av folder/ root@203.0.113.10:/root/folder/

To see which port your SSH server is currently listening on, run this on the server:

ss -tlnp | grep ssh

Save the port in your SSH config

So you don’t have to remember the port, add the server to ~/.ssh/config on your own computer:

Host myserver
 HostName 203.0.113.10
 User root
 Port 2222

After that, ssh myserver is enough. scp and rsync read this file too.

Why change the SSH port?

A port other than 22 keeps a lot of automated brute force attempts away, because bots mostly probe well-known ports. It is not real security, but your logs get much quieter. You should still protect the server with SSH keys and tools like Fail2Ban.

Change the SSH port in Vionity

SSH settings in the Cloud Manager
VionityCP SSH Settings
  • Open the Cloud Manager of the server whose SSH port you want to change.
  • Click ?VPS Settings? and open the ?SSH? tab.
  • Enter the port you want in the ?Change SSH Port? field. Use a free port above 1024.
  • Click ?Save?. The configuration is updated in the background and the SSH server restarts.

Important: If you run your own firewall (ufw, nftables, firewalld), open the new port first, for example with ufw allow 2222/tcp. If you forgot, you can still reach the server via VNC and fix it.

Change the SSH port manually

  1. Open the new port in your firewall, see above.
  2. Open /etc/ssh/sshd_config, for example with nano. Find the line with Port. If it starts with #, remove the character, otherwise the line is ignored. If it doesn’t exist, add it near the top, for example Port 2222. Pick a port between 1024 and 65535.
  3. Check the configuration with sshd -t. If it prints nothing, everything is fine.
  4. Restart the SSH server with systemctl restart ssh (on some systems the service is called sshd). Don’t close your current SSH window yet.
  5. Test the connection in a second window with ssh -p 2222 ?. If something goes wrong, fix it through the first session that is still open.
Excerpt from the file /etc/ssh/sshd_config
The /etc/ssh/sshd_config file

Ubuntu 24.04: The port doesn’t change?

Newer Ubuntu releases (22.10 and later) start SSH through a systemd socket. Restarting the service is not enough there, and SSH keeps listening on port 22. After changing sshd_config you need:

systemctl daemon-reload
systemctl restart ssh.socket
ss -tlnp | grep ssh

Systems with SELinux

If SELinux is active, for example on distributions from the Red Hat family, sshd may only use the new port after you allow it: semanage port -a -t ssh_port_t -p tcp 2222

When not to change the SSH port

If a DDoS filter protects your server and it runs a service that needs this protection, keep SSH on port 22. The firewall only reliably recognizes SSH traffic on the default port. On another port it may misclassify it. Your connection then drops suddenly and your IP address is blocked for a few minutes.