← Linux and the Command Line Lesson 36 of 51 · 5 XP

Users: useradd and su

Theory

Machine translation, not yet reviewed by a native speaker.

root is the administrator with unlimited rights; its UID = 0. Ordinary users start at UID 1000. System "users" like www-data and postgres are there so that services run with minimal rights.

Creating users (Debian, Ubuntu, Kali):

sudo useradd -m -s /bin/bash kai     # -m create a home folder, -s the shell
sudo passwd kai                       # set a password
sudo adduser kai                      # the same, but interactive and more convenient (Debian)
sudo userdel -r kai                   # delete together with the home folder

Where this is stored:

  • /etc/passwd — the list of users (you took it apart with cut);
  • /etc/shadow — password hashes, readable only by root;
  • /etc/group — the groups.

su and sudo — working as another user:

su kai               # become kai (you need THAT USER'S password)
su -                 # become root with root's full environment
sudo command         # run one command as root (you need YOUR password, and you must be in the sudo group)
sudo -i              # an interactive root shell
exit                 # go back
whoami               # who am I now

A security rule: don't work as root all the time. Use an ordinary user and sudo for individual commands. On your VPS, create a user for everyday work and log in as that user with an ssh key. It's better to turn off root login with a password in /etc/ssh/sshd_config: PermitRootLogin prohibit-password.

In BusyBox the command is adduser instead of useradd, and su is there.

Sign up for free to mark finished lessons and track your progress.