1. Create an administrator account
In your existing root session, installsudo if needed and create a user. The example uses admin; choose another name if that account already exists.
sudo, even after SSH password login is disabled.
2. Add your SSH public key
On your own computer, generate a key if you do not already have one:- With ssh-copy-id
- Manual copy
From your computer, copy the public key to the new account. Replace Enter the new user’s password when asked. If SSH password authentication is already disabled, use the manual method instead.
YOUR_VPS_IP:3. Test the new account
Open a second terminal on your computer and connect using the key:root. If either login or sudo fails, fix it before changing the SSH configuration.
4. Disable root and password login
Back up/etc/ssh/sshd_config and any files you will edit in /etc/ssh/sshd_config.d/. Review the Include line and existing settings: OpenSSH generally uses the first value it reads for an option, so adding a conflicting line at the end may not work.
On a standard Debian/Ubuntu configuration that includes /etc/ssh/sshd_config.d/*.conf, create an early settings file such as /etc/ssh/sshd_config.d/00-local-access.conf. If that file already exists, review it before editing. Set:
sshd -t means the syntax check passed. The second command should show the four intended values. Existing Match rules can change settings for particular users or addresses; review those rules too.
If the checks pass, reload SSH on Debian/Ubuntu:
sudo test before closing your original session. If it fails, restore the changed file through the open session or console, run the syntax check and reload again.