Fundamentals — Cheat Sheet
Linux · 3 topics. Download the PDF or the Instagram carousel and share it.
Cheat Sheet · AiCanCode.org
Fundamentals
Linux3 topicsQuick revision reference
1
Linux Filesystem Hierarchy
Everything in Linux is a file. The Filesystem Hierarchy Standard (FHS) defines a single tree rooted at / — knowing where things live makes you fast on any Linux system.
- ✓Linux has a single directory tree rooted at / — no drive letters.
- ✓/etc stores configuration, /var/log stores logs, /home stores user data.
- ✓/proc and /sys are virtual filesystems — kernel and hardware state as readable files.
- ✓Everything in Linux is represented as a file: disks (/dev/sda), processes (/proc/PID), sockets.
- ✓Absolute paths start with /; relative paths start from the current directory.
Linux directory hierarchy
/ (root) ├── bin/ → essential user binaries (ls, cp, mv, bash) — always available ├── sbin/ → system binaries for root (fdisk, ifconfig, reboot) ├── etc/ → system-wide configuration files (nginx.conf, sshd_config, hosts) ├── home/ → user home directories (/home/akshay, /home/alice) ├── root/ → root user's home directory ├── var/ → variable data: logs, caches, spool files │ ├── log/ → system and app logs (syslog, nginx/access.log, auth.log) │ â””── run/ → runtime PID files and sockets ├── tmp/ → temporary files, cleared on reboot ├── usr/ → user programs (the bulk of installed software) │ ├── bin/ → most user commands (python3, git, vim, curl) │ ├── lib/ → shared libraries (.so files) │ â””── local/→ locally compiled software (not managed by package manager) ├── opt/ → optional third-party software (JetBrains, custom installs) ├── proc/ → virtual FS — live kernel and process info (/proc/cpuinfo) ├── sys/ → virtual FS — hardware and kernel parameters (/sys/class/net) ├── dev/ → device files (disks, terminals, /dev/null, /dev/random) ├── lib/ → shared libraries needed by /bin and /sbin ├── boot/ → bootloader and kernel images (vmlinuz, initrd) â””── mnt/ → temporary mount points for external filesystems
2
File Permissions & Ownership
Linux file permissions control who can read, write, or execute every file. Understanding rwx, octal notation, chmod, chown, and setuid is critical for security and system administration.
- ✓Permissions are three groups of rwx: owner, group, others.
- ✓Numeric: r=4, w=2, x=1. Common: 755 (binaries), 644 (configs), 600 (private keys).
- ✓chmod changes permissions; chown changes file ownership.
- ✓setuid on executables: runs with the file owner's privileges (e.g., passwd runs as root).
- ✓Sticky bit on directories: only the file owner can delete their own files (used on /tmp).
- ✓SSH will refuse to use a private key that is not 600 or 400 — "bad permissions" error.
Reading ls -l permission output
ls -la /etc/nginx/nginx.conf # -rw-r--r-- 1 root root 2691 Jan 15 10:23 nginx.conf # │└─┬──┘└─┬──┘└─┬──┘ # │ owner group others # │ # â””── file type: # - = regular file # d = directory # l = symbolic link # b = block device # c = character device # Permission bits: r=read w=write x=execute # rw- r-- r-- # 110 100 100 ↠binary # 6 4 4 ↠octal = 644 # Common permission patterns: # 755 rwxr-xr-x binaries, directories (owner full, others read+execute) # 644 rw-r--r-- config files (owner read-write, others read-only) # 600 rw------- private keys, secrets (owner only) # 777 rwxrwxrwx âš ï¸ world-writable — security risk, avoid in production # 400 r-------- read-only secrets (SSH private keys) ls -la ~/.ssh/ # -rw------- 1 akshay akshay 1823 Jan 10 id_rsa ↠600: good # -rw-r--r-- 1 akshay akshay 399 Jan 10 id_rsa.pub ↠644: good
3
Users, Groups & sudo
Linux multi-user system — every process runs as a user, every file has an owner. Understanding users, groups, /etc/passwd, /etc/shadow, and sudo is essential for system administration and security.
- ✓Every process runs as a UID; every file has an owner UID and group GID.
- ✓System users (UID < 1000) run services — they have /sbin/nologin shell (no interactive login).
- ✓/etc/passwd is world-readable; /etc/shadow (password hashes) is root-only.
- ✓usermod -aG adds a user to a group without removing existing groups (-a = append).
- ✓Always edit /etc/sudoers with visudo — it validates syntax before saving.
- ✓Prefer /etc/sudoers.d/ drop-in files to reduce risk of breaking the sudoers file.
bash — user and group management
# Create users useradd -m -s /bin/bash akshay # -m: create home, -s: shell useradd -r -s /sbin/nologin www-data # system user (no login shell) adduser akshay # interactive (Ubuntu/Debian) # Set/change password passwd akshay # interactive echo "newpass" | passwd --stdin akshay # non-interactive (scripting) # Modify a user usermod -aG docker akshay # add akshay to docker group (append, don't replace) usermod -aG sudo akshay # grant sudo access on Debian/Ubuntu usermod -s /bin/zsh akshay # change shell usermod -L akshay # lock account (disable password login) usermod -U akshay # unlock account # Delete user userdel akshay # keep home directory userdel -r akshay # delete home and mail spool too # Groups groupadd developers groupdel developers groups akshay # list groups for user id akshay # uid, gid, and all groups # Who is logged in? who # current sessions w # with what they're doing last # login history
Learn this free with Aria, your AI tutor → AiCanCode.org/learn/linux