SSH normally listens on TCP port 22. You can move it to another port for a planned network configuration, but the change must preserve a working administration connection.
Prepare access
Choose an unused port between 1024 and 65535 and check the server’s listeners. Registry information alone does not tell you whether a port is already used on your server.
sudo ss -ltnpKeep the current session open and confirm access to a recovery console. Allow the new port in the active host firewall and any provider firewall before changing SSH. Keep the old port allowed until the new connection is verified.
Review the SSH configuration
Back up /etc/ssh/sshd_config and any included configuration files. Check their existing Port and ListenAddress settings.
For a service-managed daemon, you can temporarily listen on both ports:
Port 22
Port 2222Replace 2222 with the chosen port. Confirm that an existing ListenAddress with an explicit port or an included file does not prevent the intended listener.
Validate the configuration before applying it:
sudo /usr/sbin/sshd -tResolve errors before continuing.
Apply using the installed service model
On a service-managed system, reload its actual SSH service, normally sshd on RHEL-family distributions or ssh on Debian and Ubuntu.
Some Ubuntu releases use socket activation. In that setup, restarting only the SSH service may not change the listening port. Check ssh.socket and follow the installed release’s socket configuration instructions, including any existing socket overrides.
On SELinux-enforcing systems, the new port also needs the appropriate ssh_port_t policy assignment. Do not disable SELinux to bypass that requirement.
Test and finish
From a separate terminal:
ssh -p 2222 [email protected]Use the real username, hostname and port. Confirm login and required administrator access. Only then remove the old listener and firewall allowance if that is part of the plan, validate again and retest.
Changing the port may reduce routine scans, but it does not replace strong authentication and timely updates.