appzasGamesToolsDevLearnCheat sheetsQuick calcsConvertersReferenceNetworkTimeCalculatorsCompareLLM prices

Users, groups and sudo

Lesson 3 of 410 minIntermediate

Create accounts, share access with groups and give limited admin rights safely.

Every process runs as a user. root can do anything, so daily work should use a normal account that borrows root powers only when needed.

sudo adduser ana                 # create a user (Debian and Ubuntu)
sudo usermod -aG docker ana      # add ana to the docker group
id ana                           # show uid, gid and groups
sudo passwd -l ana               # lock the password

CarefulAlways use -a (append) with -G in usermod. Without -a, the user is removed from every other group.

sudo

sudo runs one command as root after you confirm with your own password, and logs it. It is controlled by /etc/sudoers. Edit it only with visudo, which checks the syntax before saving.

# /etc/sudoers.d/deploy  (create with: sudo visudo -f /etc/sudoers.d/deploy)
deploy ALL=(root) NOPASSWD: /bin/systemctl restart myapp

That line lets the user deploy restart only one service, with no password. Give the narrowest rule that does the job.

Files that matter

  • /etc/passwd: user list (no passwords here).
  • /etc/shadow: password hashes, readable only by root.
  • /etc/group: group membership.

NotePrefer SSH keys and disable direct root login over SSH. Use sudo so every administrative action leaves a trace in the log.

Test yourself

Answer all the questions, then check them. Finish with every answer right to mark the lesson as done.

1. What happens with usermod -G docker ana (no -a)?
2. How should you edit /etc/sudoers?
HintA two-letter command.

Key terms