From point A to point B
Point A: you work with your own user and, when something blocks you, you try sudo or chmod 777 without being quite sure why it works. Point B: by the end of this chapter you will understand the types of users, create users and groups, read and assign permissions precisely, use special permissions, tell hard links from symbolic links, and connect to other machines securely with SSH.
This is the last chapter of the course and the one you will notice most day to day: almost every security incident starts with one permission too many.
Types of users and where they are stored
- root (UID 0): the superuser. It can do anything, including breaking the system.
- System users (usually UID below 1000): accounts for services such as
www-dataorsshd. They do not log in; they exist so that each service runs with the minimum permissions. - Regular users (usually UID from 1000 up): the people.
| File | Contents | Who can read it |
|---|---|---|
/etc/passwd | Users: name, UID, GID, home directory and shell | Everyone |
/etc/shadow | Encrypted passwords (hashes) and their expiration | Only root |
/etc/group | Groups and their members | Everyone |
/etc/skel/ | Template copied into the home directory of every new user | Everyone |
id # your UID, GID and groups
whoami # your user name
groups # your groups
who # who has a session open
w # who is logged in and what they are doing
last # latest logins
getent passwd jesus # a user's line
getent group sudo # the members of a group
Privileges: sudo and su
sudo apt update # runs ONE command as root, with YOUR password
sudo -i # opens a root shell (use it as little as possible)
su - ana # switches to user ana, with ana's password
su - # switches to root, with root's password
sudo is the recommended option: every use is logged, there is no need to share the root password, and you control who can use it in /etc/sudoers (always edited with visudo). Ubuntu comes with it configured out of the box; on Debian, if you set a root password during installation, you will need to add your user to the sudo group.
Creating and managing users and groups
sudo groupadd teachers
sudo useradd -m -s /bin/bash -G teachers lucia # -m creates /home/lucia · -s their shell · -G extra groups
sudo passwd lucia # sets the password
sudo usermod -aG docker lucia # ADDS a group (without -a, it replaces them all)
sudo passwd -l lucia # locks the account
sudo passwd -u lucia # unlocks it
sudo userdel -r lucia # deletes the user and their home directory
sudo groupdel teachers
On Debian and Ubuntu there is also adduser, which is more interactive. Groups in Linux have no hierarchy: a user has one primary group and can belong to several secondary ones.
Permissions: read, write and execute
Every file has three sets of permissions: for its owning user (u), for its group (g) and for everyone else, the others (o).
How to read an ls -l line and its octal equivalent. Diagram: The House of Routing.
ls -l
# -rwxr-x--- 1 jesus devops 127 oct 19 15:10 backup.sh
# drwxr-xr-x 2 jesus jesus 4096 oct 19 20:47 project
ls -ld project # permissions of the directory, not its contents
Changing permissions with chmod
chmod u+x backup.sh # adds execute for the owner
chmod g-w,o-r report.txt # removes write from the group and read from others
chmod a+r public.txt # read for everyone (a = u+g+o)
chmod u=rwx,g=rx,o= backup.sh # assigns exactly
chmod 750 backup.sh # the same in octal
chmod 644 notes.txt # typical for a file: rw-r--r--
chmod 755 scripts/ # typical for a directory: rwxr-xr-x
chmod -R g+w project/ # recursive
Owners: chown and chgrp
sudo chown ana report.txt # changes the owning user
sudo chown ana:devops report.txt # user and group at once
sudo chgrp devops report.txt # only the group
sudo chown -R www-data:www-data /var/www/site # recursive
newgrp devops # opens a shell with devops as the primary group
Special permissions: SUID, SGID and sticky bit
| Permission | Octal | In ls -l | Effect |
|---|---|---|---|
| SUID | 4 | rwsr-xr-x | On an executable: it runs with its owner's permissions. That is how passwd can write to /etc/shadow. |
| SGID | 2 | rwxr-sr-x | On an executable: it runs with its group. On a directory: whatever is created inside inherits the directory's group. |
| Sticky bit | 1 | rwxrwxrwt | On a directory: each user can only delete their own files. This is the case with /tmp. |
ls -l /usr/bin/passwd # -rwsr-xr-x root root ... the s of SUID
ls -ld /tmp # drwxrwxrwt root root ... the t of the sticky bit
mkdir shared
chmod 2775 shared # SGID on a team directory
chmod 1777 shared # sticky bit, like /tmp
chmod g+s,o+t shared # SGID and sticky bit in symbolic notation
If the special bit is set but the corresponding execute permission is missing, you will see the letter in uppercase: S or T.
fdisk to "save yourself" the sudo. To audit your system: find / -perm -4000 -type f 2>/dev/null.Temporary directories
/tmp is for short-lived temporary files, and many distributions empty it on reboot. /var/tmp is also temporary but survives reboots. Both have the sticky bit.
Hard and symbolic links
A hard link is another name for the same data; a symbolic link stores a path. Diagram: The House of Routing.
ln notes.txt hard-copy # hard link
ln -s /etc/hosts hosts-shortcut # symbolic link
ln -s /var/www/site web # symbolic link to a directory
ls -li # -i shows the inode number
| Hard link | Symbolic link | |
|---|---|---|
| What it is | Another name for the same inode | A small file that stores a path |
| If you delete the original | The data is still accessible | The link is broken |
| To directories | No | Yes |
| Across file systems | No | Yes |
Remote access with SSH
Servers and cloud machines are administered remotely with SSH (Secure Shell), which encrypts the whole session. Version 2.0 of the exam includes it in this block.
ssh jesus@192.168.1.20 # logs in to another machine
ssh -p 2222 jesus@server.example # on a port other than 22
ssh-keygen -t ed25519 # creates your key pair (~/.ssh/id_ed25519 and .pub)
ssh-copy-id jesus@192.168.1.20 # installs your public key on the server
scp report.pdf jesus@192.168.1.20:/home/jesus/ # copies a file
sftp jesus@192.168.1.20 # interactive transfer session
With keys you no longer need a password: the server stores your public key in ~/.ssh/authorized_keys and your private key never leaves your machine.
~/.ssh has 700 permissions and the private key 600. On servers exposed to the internet, disable password login and direct root login.Linux Essentials-style challenge
Answer before you open the solution. Getting it wrong here is the cheapest way to learn.
1. What permissions does a file with mode 640 have?
rw-r-----: the owner reads and writes, the group only reads and others have no access.
2. Which file holds the users' encrypted passwords?
/etc/shadow, which only root can read. /etc/passwd is readable by everyone and contains no passwords.
3. Everyone can write to /tmp. What stops one user from deleting another user's files?
The sticky bit (the t in drwxrwxrwt): only a file's owner can delete it.
4. You delete the original file of a symbolic link. What happens to the link?
It breaks, because it only stored the path. With a hard link, the data would still be accessible.
What you take away
- root (UID 0), system users and regular users; they are stored in
/etc/passwd,/etc/shadowand/etc/group. sudofor a single command, with logging; least privilege, always.useradd -m,passwd,usermod -aGandgroupaddmanage accounts.- r=4, w=2, x=1 for user, group and others:
chmod 750isrwxr-x---. - SUID, SGID and sticky bit: powerful, and SUID, dangerous.
- Hard link: same inode. Symbolic: a path that can break.
- SSH with ed25519 keys, with no passwords and no remote root.
With this you complete the Linux Essentials syllabus. The next step on the path is Docker, where everything you have learned (processes, permissions, networking and the command line) applies to containers.
Official resources
- chmod(1)man7.org
- useradd(8)man7.org
- shadow(5)man7.org
- ln(1)man7.org
- OpenSSH manual pagesopenssh.com
- sudoers manualsudo.ws
- Linux Essentials 2.0 objectiveswiki.lpi.org
Source and credits. Chapter written from Jesús Espinoza's study notes for the LPI Linux Essentials certification (2022), updated to version 2.0 of the exam (010-200). Text drafted with AI assistance; original diagrams by The House of Routing. Technical details were checked against the official documentation from LPI, GNU and the distributions.