Logging in only as root is convenient but risky. This guide shows how to create a dedicated user with sudo and SSH key access — a great complement to Secure SSH and UFW.
📋 Prerequisites
- A Linux VPS (Ubuntu/Debian) with root or sudo access and an active SSH session.
Create the user
Replace deploy with your preferred username:
Bashsudo adduser deploy sudo usermod -aG sudo deploy
Add to the sudo group
Bashsudo groups deploy # doit afficher : deploy sudo (ou wheel sur certaines distros)
Set up an SSH key
On your PC, generate a key if needed (ssh-keygen -t ed25519). Then copy it to the server (as root, or as the new user once sudo works):
Bashssh-copy-id deploy@IP_DU_VPS
Puis connectez-vous : ssh deploy@IP_DU_VPS
Test sudo
Bashsudo apt update # ou : sudo whoami → root
Best practices
- Disable root password login after testing (see Secure SSH).
- Keep the SSH port allowed in UFW.
- Use strong passwords if you keep password authentication as a fallback.
Happy deploying! 🚀