LESSON · 1 OF 6

Users and groups

Users and groups

Every process on a Linux machine runs as some user. Every file belongs to a user. That's how the system decides who can read what.

Who am I

You already met whoami. Its sibling id gives the fuller picture:

bash
whoami          # just the username
id              # username, user ID, primary group, secondary groups

A typical id output looks like uid=0(root) gid=0(root) groups=0(root).

Users live in /etc/passwd

Each user has one line in /etc/passwd, colon-separated:

username:x:UID:GID:full name:home directory:login shell
root:x:0:0:root:/root:/bin/bash
ubuntu:x:1000:1000:Ubuntu:/home/ubuntu:/bin/bash

The x is a leftover from the days when the password hash lived there. Now hashes are in /etc/shadow, which only root can read.

Two kinds of user

Regular users own their own home folder under /home/<name> and can run everyday commands. root is the superuser: UID 0, unrestricted, owns most of the system, and can undo anything.

On production servers you almost never log in directly as root. You log in as yourself and use sudo for the moments when root permissions are actually needed.

bash
sudo apt update             # run this one command as root
sudo -i                     # start an interactive root shell

On this lab machine you're already root, so sudo is a no-op here. The habit still matters everywhere else.

Groups

Groups let several users share access to a resource. Every user has one primary group (the GID in /etc/passwd) and can be a member of any number of secondary groups, listed in /etc/group. When you look at file ownership in the next node, you'll see both a user and a group next to each file.

Spin up a fresh environment and practice live.
linux-devops-basic · fresh machine · ready in under a minute