Almost every server-hardening guide says "move SSH off port 22." People who do it usually see attack attempts in their logs drop sharply the next day and conclude the server is now protected. In reality, changing the port gives you something different: less noise, not a security layer. Here is what it does, what it does not do, and how to do it without locking yourself out.
What a new port actually changes
Most automated bots only probe the default port 22 because it is the cheapest target. Move SSH to 2222 or 49222 and those bots stop seeing your server, so thousands of "Failed password" lines in auth.log shrink to a handful. Logs become readable, a little disk and CPU work disappears, and genuinely suspicious activity is much easier to spot among the few entries that remain.
A targeted attacker, however, is not slowed down. Masscan or Nmap can sweep all 65535 ports of one IP quickly, and Shodan continuously indexes which port runs SSH. The server announces itself with an SSH-2.0-OpenSSH_... banner, so it is easy to recognise on any port. A non-standard port avoids lazy bots; it hides nothing.
What real protection looks like
SSH security comes from authentication, not the port number. With password login disabled and keys only, thousands of attempts on port 22 achieve nothing. The right order is keys first, then restricting root, then Fail2ban or firewall rules. The port change is an optional convenience at the end of that list.
Example: a clinic server in Samarkand
A private clinic in Samarkand runs online booking on a VPS. The admin moves SSH to 2222 and the logs get much cleaner. A month later someone logs straight into the new port with a password stolen from a staff computer, because password login was still enabled. The port change did not stop anything; it only made the logs quieter.
Changing the port safely
Open the new port in the firewall first, change the setting, and test the new port before closing your current session. On Ubuntu with UFW:
sudo ufw allow 2222/tcp
echo "Port 2222" | sudo tee /etc/ssh/sshd_config.d/10-port.conf
sudo sshd -t
sudo systemctl restart ssh
ss -tlnp | grep ssh
On AlmaLinux or Rocky Linux, SELinux only lets SSH bind to approved ports, so register the new one and open it in firewalld:
sudo semanage port -a -t ssh_port_t -p tcp 2222
sudo firewall-cmd --permanent --add-port=2222/tcp
sudo firewall-cmd --reload
sudo systemctl restart sshd
Newer Ubuntu releases often start SSH through ssh.socket. If ss -tlnp still shows the old port, run sudo systemctl daemon-reload and sudo systemctl restart ssh.socket, and check the Ubuntu documentation for your version. Remove the port 22 rule only after the new port works. If something does go wrong, the VPS console in your control panel lets you log in and revert the change, so find it before you start rather than in a panic afterwards.
Choosing a number and configuring the client
Pick a port that does not clash with other services. Ports below 1024 can only be bound by root, so if sshd ever stops, an unprivileged user cannot start a fake service there; on a single-admin VPS this risk is small either way. Save typing with an entry in ~/.ssh/config, which SFTP clients also respect:
Host klinika
HostName example.uz
User deploy
Port 2222
IdentityFile ~/.ssh/id_ed25519
When it does not apply
On shared hosting the SSH port is set by the provider and you cannot change it, which is normal. Focus on strong passwords, keys where available, and the security of your own computer. Questions about SSH or SFTP details for sayt.uz hosting can be answered through the cabinet or support. On a VPS a new port does no harm; just treat it as a small convenience on top of real protection, not a replacement for it.