SSH Tweaks¶
This documentation contains various notes on SSH configurations on a Debian server. (At the time of writing, based on Debian 13.)
Let the bootstrap script do the work for you!
Don’t bother doing this manually, our Debian bootstrap script can do this for you if you’re setting up a fresh Debian server. Check the script’s README for details and instructions.
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:
- Find 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:
Disable password-based SSH login¶
Changing this setting enforces using SSH keys to login, password logins will be blocked.
- Open the SSH daemon configuration:
- Find 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:
Change SSH port¶
Changing this setting changes the port that the built-in SSH server listens on.
Warning
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:
- Find 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:
Install Fail2Ban¶
For additional SSH security, consider installing Fail2Ban.