The first 15 minutes on a new VPS come down to seven steps: update packages, create a user with adduser, grant sudo with usermod -aG sudo, install your public key, test it in a second session, disable password and root login in sshd_config, and enable ufw with port 22 open.
The commands use Debian and Ubuntu syntax. You start with root access, either by password or with a key injected by your provider. One rule applies throughout: do not close the root session until you have logged in as the new user with its key.
Updating a new VPS before touching SSH: apt and unattended-upgrades
The first command on a freshly created VPS is a package upgrade, because the provider's image may have gone a while without patches, OpenSSH included.
apt update && apt upgrade -y
apt install unattended-upgrades
dpkg-reconfigure -plow unattended-upgradesThe last command turns on automatic security updates; answer Yes. On a phone, run the upgrade inside tmux: if the network drops, it keeps running and you get it back with tmux attach. If a new kernel lands, reboot with reboot once everything else is done.
Creating the VPS user with adduser and usermod -aG sudo
adduser creates the user and its home directory and asks for a password; usermod -aG sudo adds it to the sudo group without removing it from any other.
adduser deploy
usermod -aG sudo deploy
groups deployThe -a matters: without it, -G replaces the list of supplementary groups instead of appending one. Store the password in your manager: it will not log you in over SSH, but sudo will ask for it. On Red Hat-family systems the equivalent group is wheel.
SSH keys for the VPS: generate Ed25519 and fill authorized_keys
OpenSSH has supported Ed25519 keys since version 6.5 (January 2014), and since OpenSSH 8.8 (September 2021) the SHA-1 ssh-rsa signature is disabled by default. With a FIDO2 key, ed25519-sk works from OpenSSH 8.2.
ssh-keygen -t ed25519 -C 'deploy@laptop'
ssh-copy-id -i ~/.ssh/id_ed25519.pub [email protected]If ssh-copy-id is unavailable or the key lives on your phone, paste the public key by hand from the root session. Expected permissions are 700 for ~/.ssh and 600 for authorized_keys; with looser permissions, sshd ignores the file.
mkdir -p /home/deploy/.ssh
nano /home/deploy/.ssh/authorized_keys
chmod 700 /home/deploy/.ssh
chmod 600 /home/deploy/.ssh/authorized_keys
chown -R deploy:deploy /home/deploy/.sshIn termi1 the key is generated on the iPhone or Android device itself and stored in the system's secure storage; the private key never leaves the device and is never sent to termi1 servers. You only copy the public half.
Test before moving on: open a second session with ssh [email protected], run sudo -v and confirm the key gets you in. The root session stays open as your safety net.
Disabling SSH passwords on the VPS in sshd_config without locking yourself out
Three directives in /etc/ssh/sshd_config shut off password and root logins; the official sshd_config manual page documents each one.
# /etc/ssh/sshd_config
PermitRootLogin no
PasswordAuthentication no
KbdInteractiveAuthentication noCheck /etc/ssh/sshd_config.d/ as well: some cloud images ship files there that turn PasswordAuthentication back on, and sshd uses the first value it reads. Validate before reloading; if sshd -t prints nothing, the config is valid.
sudo sshd -t
sudo systemctl reload sshOn Debian and Ubuntu the service is called ssh; elsewhere it is usually sshd. A reload does not drop open sessions. From another session, confirm that ssh [email protected] is refused and that deploy still gets in.
VPS firewall with ufw: SSH on port 22 and Mosh on 60000-61000/udp
OpenSSH listens on TCP port 22 by default, and that rule must exist in ufw before ufw enable; otherwise the firewall cuts the very connection you used to turn it on.
sudo ufw default deny incoming
sudo ufw default allow outgoing
sudo ufw allow 22/tcp
sudo ufw allow 60000:61000/udp
sudo ufw enable
sudo ufw status verboseThe UDP rule is only needed for Mosh, which starts mosh-server over an initial SSH connection and then talks UDP on ports 60000-61000, as the official Mosh documentation explains. Mosh does no port forwarding or X11 forwarding, so tunnels still go over SSH. If you would rather expose nothing, a private mesh network such as Prialo or Tailscale reaches the VPS without opening ports.
Hardening a VPS from a phone vs a desktop: comparison table
All seven steps can be done from a phone; what changes is how you handle the keyboard, the network and typing mistakes.
| Task | iOS/Android phone with termi1 | Desktop with OpenSSH client |
|---|---|---|
| Generate the Ed25519 key | On the phone; private key stays in secure storage | ssh-keygen; private key stays in ~/.ssh with 600 permissions |
| Edit sshd_config in nano or vim | Custom keyboard with Esc, Ctrl, Tab and arrows | Full physical keyboard |
| Network change during the upgrade | Mosh keeps the session when switching from wifi to mobile data | An SSH session drops if the IP changes |
| Upload authorized_keys or config files | Built-in SFTP without leaving the session | scp, which uses SFTP by default since OpenSSH 9.0 |
| Commands that delete or stop things | Production Guard holds them before the prompt | Relies on the care of whoever types |
For long commands, termi1's AI turns a typed or dictated sentence into a command that is written at the prompt without pressing Enter; in Review mode it never presses it. If you tag the VPS as production, nothing gets Enter automatically. The AI does not open the session and never receives keys or passwords. The terminal works without an account, and you can download termi1 for iPhone for free.
Frequently asked questions
What does usermod -aG sudo do on Ubuntu?
The usermod -aG sudo command adds a user to the sudo group without removing it from its other supplementary groups. The -a flag means append; without it, -G replaces the whole group list. The user must log out and back in for the new group to apply.
Which ports does ufw need to open for Mosh?
Mosh needs TCP port 22 for the initial SSH connection that starts mosh-server and, by default, the UDP range 60000-61000 for the session itself. In ufw, running ufw allow 22/tcp and ufw allow 60000:61000/udp before ufw enable is enough.
How do I avoid locking myself out of a VPS when disabling passwords?
To avoid locking yourself out of a VPS when disabling passwords, keep the root session open, confirm in a second session that the new user logs in with its key, validate with sshd -t, and only then reload the ssh service.
Why use an Ed25519 key instead of RSA?
An Ed25519 key is short and supported by every OpenSSH release since 6.5, from January 2014. RSA keys still work with SHA-2 signatures, but since OpenSSH 8.8 the SHA-1 ssh-rsa signature is disabled by default, which affects older clients.