SSH Tweaks¶
This documentation contains various notes on SSH configurations on a Debain server. (At the time of writing, based on Debian 13.)
Disable root SSH login¶
Whenever possible, we want to prevent root from logging in via SSH to avoid any potential security issues.
Open the SSH daemon configuration:
sudo nano /etc/ssh/sshd_configFind the
PermitRootLoginline, uncomment it if needed, and change the option tono.Save and close the file with Ctrl+X, Y to confirm, and Enter to select the save location.
Restart the SSH server:
sudo systemctl restart ssh
Disable password-based SSH login¶
Changing this setting enforces using SSH keys to login, password logins will be blocked.
Open the SSH daemon configuration:
sudo nano /etc/ssh/sshd_configFind the
PasswordAuthenticationline, uncomment it if needed, and change the option tono.Save and close the file with Ctrl+X, Y to confirm, and Enter to select the save location.
Restart the SSH server:
sudo systemctl restart ssh
Change SSH port¶
Changing this setting changes the port that the built-in SSH server listens on.
Attention
Once you change the SSH port, you’ll need to specify the new (non-default) port when connecting directly via SSH. Use the command ssh -p 2222 user@server where 2222 is your updated SSH port.
Open the SSH daemon configuration:
sudo nano /etc/ssh/sshd_configFind the
Port 22line, uncomment it if needed, and change the option to2222(or your desired port).Save and close the file with Ctrl+X, Y to confirm, and Enter to select the save location.
Restart the SSH server:
sudo systemctl restart ssh