SSH Hardening Tutorial: Port Change and Key Login
This tutorial walks through hardening SSH on a VPS with xyz.sh/ssh without locking yourself out.
$ curl -fsSL xyz.sh/ssh | bash
Details · xyz.sh/ssh · Last updated:
Prerequisites
Root access and an SSH session you keep open.
A public key if you will disable passwords (for example the keys on your GitHub account).
Know where your provider's security group and VNC/console are.
Steps
Optional: read the source with curl -fsSL xyz.sh/ssh.sh and compare xyz.sh/ssh.sh.sha256.
Show current settings: curl -fsSL xyz.sh/ssh | bash -s -- --status
Add a port (old one kept): curl -fsSL xyz.sh/ssh | bash -s -- --port 2222 -y, open 2222 in the security group, and test ssh -p 2222 from a new terminal.
Import keys and disable passwords: curl -fsSL xyz.sh/ssh | bash -s -- --github yourname --disable-password -y
After the new port works, close the old one: curl -fsSL xyz.sh/ssh | bash -s -- --port 2222 --close-old -y
How to verify
Keep this terminal open and from a new one run ssh -p NEW_PORT user@server to confirm. curl -fsSL xyz.sh/ssh | bash -s -- --status shows the effective sshd -T values.
How to undo or uninstall
curl -fsSL xyz.sh/ssh | bash -s -- --rollback -y removes the xyz.sh block, restores commented Port lines and reloads sshd; keys added to authorized_keys are kept — remove them manually if needed.