Manage Linux users and sudo
Updated 27 Nov 2026 users sudo
Add accounts, grant administrator rights and remove access safely.
Add a user
Ubuntu and Debian:
sudo adduser asha
AlmaLinux and Rocky Linux:
sudo useradd -m asha
sudo passwd asha
Grant sudo
Ubuntu and Debian use the sudo group; AlmaLinux and Rocky use wheel:
sudo usermod -aG sudo asha # Ubuntu, Debian
sudo usermod -aG wheel asha # AlmaLinux, Rocky
The user must sign in again for the group to apply.
Add their SSH key
sudo install -d -m 700 -o asha -g asha /home/asha/.ssh
echo 'ssh-ed25519 AAAA... asha@laptop' | sudo tee /home/asha/.ssh/authorized_keys
sudo chown asha:asha /home/asha/.ssh/authorized_keys
sudo chmod 600 /home/asha/.ssh/authorized_keys
Edit sudo rules safely
Always use visudo, which checks the syntax:
sudo visudo -f /etc/sudoers.d/deploy
Allow only the command needed, for example:
deploy ALL=(root) NOPASSWD: /usr/bin/systemctl restart myapp
Remove access
sudo usermod --expiredate 1 asha # disables the account, including key sign-in
sudo deluser --remove-home asha # Ubuntu, Debian
sudo userdel -r asha # AlmaLinux, Rocky