Set up a VPS firewall without blocking your own access
List required ports, allow SSH first and test the guest and Control Panel firewall rules.
Read the guideVPS security · Practical guide
Create an SSH key, install the public key and test a new login before changing password access.
Archive placement: January 2023

SSH keys make everyday server access safer and more convenient, but only after you have proved that the right key works for the right account. This guide takes you from creating a key to testing a separate login, with a recovery route if anything goes wrong.
Connect using the method that already works, and leave that session open. Open the VPS browser console in the Control Panel too. Confirm you can reach a login prompt there; opening an empty console tab is not enough. If your recovery login is uncertain, resolve that before changing SSH.
whoami
sudo -vWrite down the server address, SSH port and account name. The examples use vpsuser and the usual port 22. A key belongs to a particular server account: installing one for root will not automatically allow vpsuser to sign in. You do not need to disable password access to start using keys.
In your local terminal, use a dedicated filename so you do not replace an existing key. The command prompts for a passphrase. Choose one you can store securely; it protects the private key if someone gets a copy of the file.
ssh-keygen -t ed25519 -f ~/.ssh/plenty_vps_ed25519There are two files. plenty_vps_ed25519 is private and stays on your computer. plenty_vps_ed25519.pub is public and is the one you install on the VPS. Never paste the private file into a control panel, email or support ticket. On Windows, OpenSSH can create the same files under your user profile’s .ssh folder.
On Linux or macOS, ssh-copy-id can add the public key to the account without replacing its existing authorised keys. Use your current account password when prompted. If the server uses a custom port, add -p followed by that port.
ssh-copy-id -i ~/.ssh/plenty_vps_ed25519.pub vpsuser@server.example.comIf ssh-copy-id is unavailable, display the .pub file locally, then use the existing server session to create ~/.ssh with permission 700. Open ~/.ssh/authorized_keys in an editor and append the public key as one complete line. Preserve any existing keys; do not replace the file. Set authorized_keys to permission 600. Both should be owned by the login account.
mkdir -p ~/.ssh
chmod 700 ~/.ssh
nano ~/.ssh/authorized_keys
chmod 600 ~/.ssh/authorized_keysOpen another local terminal. This command specifies the key and prevents a fallback to your server password or an already-open shared connection. A private-key passphrase prompt is normal. A successful login followed by whoami should show the intended account.
ssh -i ~/.ssh/plenty_vps_ed25519 -o IdentitiesOnly=yes -o ControlMaster=no -o ControlPath=none -o PreferredAuthentications=publickey -o PasswordAuthentication=no vpsuser@server.example.comIf SSH asks you to trust a new server fingerprint, compare it with a trusted record or the server’s host-key fingerprint obtained through its authenticated console. Do not accept a changed fingerprint simply because login is failing. Reinstalls can legitimately change host keys, but the change still needs checking.
sudo journalctl -u ssh.service --since "10 minutes ago" --no-pagerLook for the timestamp and username from your test. Permission or ownership warnings usually identify a specific directory or file. Make one correction and retry from the second terminal while keeping your original session available.
Only do this after key login and sudo access work in a new session. If your server uses password-based MFA or another managed authentication policy, stop and account for that first. On a standard Ubuntu setup, create a separate snippet, check its effective settings and reload the service.
sudoedit /etc/ssh/sshd_config.d/00-local-key-login.confPubkeyAuthentication yes
PasswordAuthentication no
KbdInteractiveAuthentication nosudo sshd -t
sudo sshd -T | grep -E "pubkeyauthentication|passwordauthentication|kbdinteractiveauthentication"
sudo systemctl reload ssh.serviceThe syntax check should produce no errors, and the effective settings should show yes, no and no. Included snippets and Match blocks can change the result for a particular user; resolve conflicting settings rather than assuming the last line wins. Make another fresh key login after reloading. To undo only this change, use the original session or console to rename your new snippet so it no longer ends in .conf, validate and reload again.
Store an encrypted backup of your private key and its passphrase in a place you can reach if your usual computer is lost. Give each administrator their own key so one person’s access can be removed without replacing everyone’s login. When retiring a key, remove only its matching line from authorized_keys and test the remaining access.
No. Key authentication works on port 22. A different port mainly reduces routine scan noise; it does not replace keys or firewall rules.
Yes, after a second independent login works, the expected account has the administrator access it needs, and your console recovery route is confirmed. An old open session alone does not prove the new settings work.