To secure your Linux server against automated attacks, we recommend changing the SSH port. Here we explain different ways to change the SSH port of your server.
Automated via the web interface
- Open the Cloud Manager of the server for which you want to change the SSH port.
- Click on VPS Settings.
- Open the “SSH” tab.
- In the input field “Change SSH port,” enter the desired SSH port. Make sure to use a free port above 1024.
- Click “Save” afterwards.
- In the background, the configuration will be adjusted and your SSH server will be restarted.
Important: If you use a software firewall (iptables, ufw, firewalld), you must allow the port beforehand. If you forgot to do this, you can easily fix it via VNC.
Manually edit the configuration
You can also manually edit the configuration of the SSH server. We’ll show you how.
- Connect to your Linux server via SSH.
- Open the file
/etc/ssh/sshd_config
with a text editor such as “nano”. - Find the line that contains “Port”. If it doesn’t exist, add it near the top. Make sure the line doesn’t start with “#”. If it does, remove the “#”. Otherwise, the SSH server will ignore this setting.
- Next to “Port”, write the number you want to use as the SSH server port. For example,
Port 2222
. Choose a port between 1024 and 65565.
- Save the file.
- Check with the command “ssh -T” if the configuration can be read successfully. If an error message appears, check your configuration.
- Restart the SSH server (
service ssh restart
), but do not close the SSH window yet. - Open a new SSH window and test the connection. If something doesn’t work, you can continue to use the still open first connection to solve the problem.