Filesystem Permissions Boot
Filesystem, Permissions & Boot — Quick Reference
Section titled “Filesystem, Permissions & Boot — Quick Reference”Linux Filesystem Hierarchy (FHS)
Section titled “Linux Filesystem Hierarchy (FHS)”The entire Linux filesystem is a single tree rooted at /. Everything — disks, devices, network mounts — hangs off this tree.
/├── bin → essential user binaries (ls, cp, bash) — symlink to /usr/bin on modern systems├── sbin → system binaries (fdisk, mount) — symlink to /usr/sbin on modern systems├── usr → user programs and libraries│ ├── bin → most installed programs live here│ ├── lib → shared libraries for /usr/bin│ ├── local/ → software compiled/installed outside the package manager│ └── share/ → architecture-independent data (docs, icons)├── etc → system-wide configuration files├── home → user home directories (/home/alice, /home/bob)├── root → home directory of the root user (not inside /home)├── var → variable data: logs, databases, mail, pid files│ ├── log/ → system and service logs│ ├── cache/ → cached application data│ └── run/ → runtime data (pid files, sockets)├── tmp → temporary files, cleared on reboot├── dev → device files (disks, ttys, null, random)├── proc → virtual filesystem: live kernel and process info├── sys → virtual filesystem: hardware and driver info├── run → runtime data since last boot (replaces /var/run on modern systems)├── lib → shared libraries for /bin and /sbin├── mnt → manual mount point for temporary mounts├── media → auto-mount point for removable media (USB, CD)├── opt → optional/third-party self-contained software└── boot → kernel, initrd, bootloader filesKey directories to know
Section titled “Key directories to know”| Path | What it holds |
|---|---|
/etc/passwd | User accounts (username, UID, home, shell) |
/etc/shadow | Hashed passwords (root-readable only) |
/etc/group | Group definitions |
/etc/fstab | Filesystems to mount at boot |
/etc/hostname | Machine hostname |
/etc/hosts | Local DNS override |
/var/log/syslog or /var/log/messages | General system log |
/proc/cpuinfo | CPU info (live) |
/proc/meminfo | RAM info (live) |
/proc/<PID>/ | Everything about a running process |
File Permissions
Section titled “File Permissions”Every file and directory has three permission sets: owner, group, and others.
-rwxr-xr-- 1 alice developers 4096 Jul 10 12:00 script.sh│└──┴──┴── └───┘ └────────┘│ │ │ └─ others: r-- (read only)│ │ └──── group: r-x (read + execute)│ └─────── owner: rwx (read + write + execute)└────────── file type: - = file, d = directory, l = symlinkThe 9 permission bits as a bit field — orange = owner, blue = group, yellow = others; attr row shows octal value of each bit:
Permission bits
Section titled “Permission bits”| Symbol | Octal | File meaning | Directory meaning |
|---|---|---|---|
r | 4 | Read file contents | List directory contents |
w | 2 | Write / modify file | Create, delete, rename files inside |
x | 1 | Execute as program | Enter directory (cd) |
- | 0 | Permission denied | Permission denied |
Octal quick reference
Section titled “Octal quick reference”| Octal | Binary | Symbolic | Meaning |
|---|---|---|---|
7 | 111 | rwx | Full access |
6 | 110 | rw- | Read + write |
5 | 101 | r-x | Read + execute |
4 | 100 | r-- | Read only |
0 | 000 | --- | No access |
Common permission patterns
Section titled “Common permission patterns”| Mode | Symbolic | Typical use |
|---|---|---|
644 | rw-r--r-- | Regular files, configs |
755 | rwxr-xr-x | Directories, executables |
600 | rw------- | Private keys, sensitive files |
700 | rwx------ | Private scripts/directories |
777 | rwxrwxrwx | World-writable — avoid in production |
Special permission bits
Section titled “Special permission bits”| Bit | Name | Octal | Effect |
|---|---|---|---|
s on owner execute | SetUID (SUID) | 4xxx | File runs as its owner (e.g. sudo, passwd) |
s on group execute | SetGID (SGID) | 2xxx | File runs as its group; new files in dir inherit group |
t on others execute | Sticky bit | 1xxx | Only owner can delete their own files (e.g. /tmp) |
chmod 4755 file # set SUIDchmod 2755 dir # set SGID on directorychmod 1777 /tmp # sticky bit (classic /tmp setup)ls -l /tmp # shows 'drwxrwxrwt' — t = stickychmod — Change Permissions
Section titled “chmod — Change Permissions”# Octal (absolute — sets permissions exactly)chmod 644 file.txt # rw-r--r--chmod 755 script.sh # rwxr-xr-xchmod 600 ~/.ssh/id_rsa # private key
# Symbolic (relative — adds/removes specific bits)chmod +x script.sh # add execute for allchmod -w file.txt # remove write for allchmod u+x script.sh # add execute for owner onlychmod g-w file.txt # remove write from groupchmod o-rwx file.txt # remove all from otherschmod u=rwx,g=rx,o= file.txt # set each class explicitly
# Recursivechmod -R 755 ./public/ # apply to dir and all contentschown — Change Ownership
Section titled “chown — Change Ownership”chown alice file.txt # change owner to alicechown alice:developers file # change owner + groupchown :developers file # change group onlychown -R alice:alice ./dir # recursive (all files inside)chgrp — Change Group
Section titled “chgrp — Change Group”chgrp developers file.txt # change group to 'developers'chgrp -R www-data ./public/ # recursivechgrp is equivalent to chown :group — use whichever is clearer.
Users & Groups
Section titled “Users & Groups”View users and groups
Section titled “View users and groups”id # current user's UID, GID, and groupsid alice # another user's IDswhoami # just the usernamegroups # groups the current user belongs tocat /etc/passwd # all users (username:x:UID:GID:comment:home:shell)cat /etc/group # all groups (groupname:x:GID:members)getent passwd alice # look up a user via NSS (works with LDAP too)Manage users
Section titled “Manage users”sudo useradd -m -s /bin/bash alice # create user with home dir and bash shellsudo useradd -m -G sudo,docker alice # add to groups at creationsudo passwd alice # set passwordsudo usermod -aG docker alice # add alice to docker group (-a = append)sudo usermod -s /bin/zsh alice # change shellsudo userdel alice # delete user (keep home dir)sudo userdel -r alice # delete user + home dirManage groups
Section titled “Manage groups”sudo groupadd developers # create a groupsudo groupdel developers # delete a groupsudo gpasswd -a alice developers # add alice to groupsudo gpasswd -d alice developers # remove alice from group/etc/passwd format
Section titled “/etc/passwd format”alice:x:1001:1001:Alice Smith:/home/alice:/bin/bash │ │ │ │ │ │ └── login shell │ │ │ │ │ └── home directory │ │ │ │ └── comment / full name (GECOS) │ │ │ └── primary GID │ │ └── UID │ └── password placeholder (actual hash in /etc/shadow) └── usernameRelationship between users, groups, and files:
sudo — Run as root
Section titled “sudo — Run as root”sudo command # run as rootsudo -u alice command # run as another usersudo -i # open interactive root shellsudo !! # re-run last command with sudovisudo # safely edit /etc/sudoers/etc/sudoers entry format:
alice ALL=(ALL:ALL) ALL # full sudo accessbob ALL=(ALL) NOPASSWD: /bin/systemctl restart nginx # specific command, no password%developers ALL=(ALL) ALL # grant to entire groupumask — Default Permission Mask
Section titled “umask — Default Permission Mask”umask subtracts permissions from newly created files and directories.
umask # show current mask (e.g. 0022)umask 027 # set new mask for this session| umask | New file (666 base) | New dir (777 base) |
|---|---|---|
022 | 644 (rw-r—r—) | 755 (rwxr-xr-x) |
027 | 640 (rw-r-----) | 750 (rwxr-x---) |
077 | 600 (rw-------) | 700 (rwx------) |
Files default to 666 - umask, directories to 777 - umask (execute is not set on new files).
Boot Sequence
Section titled “Boot Sequence”Overview
Section titled “Overview”Power on │ ▼┌─────────────────────────────┐│ BIOS / UEFI │ Hardware init, POST (Power-On Self Test)│ Finds bootable device │ Reads boot order from firmware settings└────────────┬────────────────┘ │ ▼┌─────────────────────────────┐│ Bootloader (GRUB2) │ Loads kernel + initrd from /boot│ /boot/grub/grub.cfg │ Shows OS selection menu└────────────┬────────────────┘ │ ▼┌─────────────────────────────┐│ Kernel (vmlinuz) │ Decompresses, initializes hardware│ + initrd / initramfs │ Temporary root FS with drivers needed to mount real root└────────────┬────────────────┘ │ ▼┌─────────────────────────────┐│ init / systemd (PID 1) │ First process started by the kernel│ /sbin/init or systemd │ Mounts real root FS, starts services└────────────┬────────────────┘ │ ▼┌─────────────────────────────┐│ systemd targets │ multi-user.target, graphical.target│ (replaces SysV runlevels) │ Starts all enabled services in parallel└────────────┬────────────────┘ │ ▼ Login promptStage 1 — BIOS vs UEFI
Section titled “Stage 1 — BIOS vs UEFI”| BIOS | UEFI | |
|---|---|---|
| Partition table | MBR (max 2 TB, 4 partitions) | GPT (9.4 ZB, 128 partitions) |
| Boot files | MBR sector on disk | EFI partition (/boot/efi) |
| Secure Boot | No | Yes (can be disabled) |
| Speed | Slower | Faster |
| 64-bit | No | Yes |
Stage 2 — GRUB2 Bootloader
Section titled “Stage 2 — GRUB2 Bootloader”cat /boot/grub/grub.cfg # GRUB config (auto-generated, don't edit directly)cat /etc/default/grub # editable GRUB settingssudo update-grub # regenerate grub.cfg after editing /etc/default/grub
# Useful /etc/default/grub settingsGRUB_TIMEOUT=5 # seconds to show menuGRUB_DEFAULT=0 # boot first entry by defaultGRUB_CMDLINE_LINUX="quiet splash" # kernel parametersGRUB rescue — if grub drops to a rescue prompt:
# At grub rescue> prompt:ls # list detected drives: (hd0), (hd0,gpt1), etc.ls (hd0,gpt2)/ # list files on a partitionset root=(hd0,gpt2)set prefix=(hd0,gpt2)/boot/grubinsmod normalnormal # boot normallyStage 3 — Kernel + initramfs
Section titled “Stage 3 — Kernel + initramfs”ls /boot/ # vmlinuz (kernel), initrd.img (initramfs), System.mapuname -r # running kernel versionls /boot/vmlinuz-* # all installed kernelsThe initramfs (initrd.img) is a minimal temporary root filesystem built into a cpio archive. The kernel unpacks it into memory, uses it to load storage drivers and mount the real root partition, then switches to the real root via pivot_root.
lsinitramfs /boot/initrd.img-$(uname -r) | head -30 # inspect initramfs contentsStage 4 — systemd (PID 1)
Section titled “Stage 4 — systemd (PID 1)”systemctl list-units --type=service # running servicessystemctl list-units --state=failed # failed unitssystemctl start|stop|restart nginx # manage a servicesystemctl enable|disable nginx # start/stop at bootsystemctl status nginx # service status + recent logsjournalctl -b # all logs from current bootjournalctl -b -1 # logs from previous bootjournalctl -u nginx # logs for a specific unitjournalctl -f # follow live logs (like tail -f)
# Boot performancesystemd-analyze # total boot timesystemd-analyze blame # time each unit tooksystemd-analyze critical-chain # the slowest path through bootsystemd targets (vs SysV runlevels)
Section titled “systemd targets (vs SysV runlevels)”| SysV Runlevel | systemd Target | Meaning |
|---|---|---|
| 0 | poweroff.target | Shutdown |
| 1 | rescue.target | Single-user / recovery |
| 3 | multi-user.target | CLI, no GUI |
| 5 | graphical.target | Full desktop |
| 6 | reboot.target | Reboot |
systemctl get-default # current default targetsudo systemctl set-default multi-user.target # boot to CLI by defaultsudo systemctl isolate rescue.target # switch to rescue mode now/etc/fstab — Persistent Mounts
Section titled “/etc/fstab — Persistent Mounts”# device mountpoint fstype options dump passUUID=abc123... / ext4 defaults 0 1UUID=def456... /boot/efi vfat umask=0077 0 1UUID=789... /home ext4 defaults 0 2tmpfs /tmp tmpfs size=1G,noexec 0 0cat /etc/fstab # view current mounts configsudo mount -a # mount all entries in fstab (test it)blkid # list UUIDs and labels of all block deviceslsblk # block device treels -lashows the full permission string — read it as[type][owner][group][others].stat fileshows octal permissions, owner, group, size, and timestamps in one shot.- Prefer
chown user:groupover runningchownandchgrpseparately. sudo !!re-runs the last command with sudo — saves retyping long commands.systemd-analyze blameis your first stop when boot feels slow.- Never set
777permissions on files served by a web server —644for files,755for directories. - The sticky bit on
/tmp(1777) means any user can write there but cannot delete others’ files. - SUID on an executable (
chmod 4755) makes it always run as its owner — review carefully before setting.