Interpret ravi:x:1002:1050:Ravi Kumar:/home/ravi:/bin/bash from /etc/passwd and ravi:!$6$Tz…:20103:1:60:7::: from /etc/shadow.
Booting takes a Linux machine from power-on through firmware (BIOS/UEFI), the MBR or GPT, a boot loader, the kernel and initramfs to init/systemd and a login prompt. User administration covers the account files, user and group commands, su/sudo and file permissions.
| Bytes (offset) | Size | Contents |
|---|---|---|
| 0 – 445 | 446 bytes | Bootstrap (boot loader stage 1) code |
| 446 – 509 | 64 bytes | Partition table: 4 entries × 16 bytes |
| 510 – 511 | 2 bytes | Boot signature 0x55, 0xAA (the word 0xAA55 in little-endian order) |
Each 16-byte partition entry holds a boot (active) flag (0x80 = bootable), the start and end addresses in old CHS form, a type code (0x83 Linux, 0x82 Linux swap, 0x07 NTFS/exFAT, 0x0B/0x0C FAT32, 0x05/0x0F extended, 0xEE GPT protective) and two 32-bit fields: the starting LBA and the number of sectors. Those 32-bit fields set the limits: at most 2³² sectors × 512 bytes = 2 TiB per disk. Only 4 primary partitions fit; to get more, one of them can be an extended partition holding logical partitions (on Linux these are numbered from /dev/sda5 onward).
GPT (GUID Partition Table), defined in the UEFI specification, removes these limits. LBA 0 still holds a protective MBR — a single partition of type 0xEE covering the whole disk, so that old tools do not think the disk is empty. LBA 1 holds the primary GPT header (disk GUID, location and number of partition entries, CRC32 checksums), followed by the partition entry array (normally 128 entries of 128 bytes, LBAs 2–33). A backup header and entry array sit at the end of the disk. Addresses are 64-bit, so a disk may reach 2⁶⁴ sectors — 8 ZiB with 512-byte sectors — and each partition has a type GUID, a unique GUID and a name.
Useful commands: lsblk and blkid list disks and partitions; fdisk (MBR and GPT), gdisk and parted edit tables; dd if=/dev/sda of=mbr.bak bs=512 count=1 saves a copy of the MBR (see the backup topic).
A boot loader loads the operating-system kernel (and its initial RAM disk) into memory, passes it parameters, and often offers a menu of kernels or operating systems (multi-boot).
| Boot loader | Facts worth knowing |
|---|---|
| LILO (LInux LOader) | The old Linux loader; config /etc/lilo.conf. It records the kernel's raw disk location and knows nothing about file systems, so /sbin/lilo must be re-run after every kernel or config change |
| GRUB Legacy (0.9x) | GRand Unified Bootloader; understands file systems; stages 1, 1.5 and 2; menu in /boot/grub/menu.lst |
| GRUB 2 | Default on most distributions. boot.img (fits the 446-byte MBR area) → core.img (in the gap after the MBR, a BIOS-boot partition, or grubx64.efi on UEFI) → modules → menu. Its /boot/grub/grub.cfg is generated by update-grub or grub2-mkconfig from /etc/default/grub and /etc/grub.d/ — do not edit it by hand |
| systemd-boot, SYSLINUX | A simple UEFI-only boot manager; SYSLINUX/ISOLINUX boot USB sticks and CDs |
| Windows Boot Manager | bootmgr with the BCD store (Windows Vista onward); Windows XP used NTLDR and boot.ini |
The loader reads the compressed kernel image (/boot/vmlinuz-…, a bzImage) and the initramfs (/boot/initrd.img-… or initramfs-….img) and passes the kernel command line, e.g. root=UUID=… ro quiet splash. The kernel decompresses itself, initialises the CPU, memory management, the scheduler and built-in drivers, then unpacks the initramfs — a compressed cpio archive — as a temporary root file system and runs its /init. That small program loads whatever modules are needed to reach the real root file system (NVMe or SATA drivers, software RAID, LVM, LUKS decryption), mounts it, and switch_roots into it. Finally the kernel executes /sbin/init as process 1.
dmesg or journalctl -k.PID 1 is the ancestor of every user process: it starts the system services, adopts orphaned processes and reaps them. If it ever dies, the kernel panics. The traditional implementation is System V init, configured by /etc/inittab, which defines runlevels — named system states.
| Runlevel | Meaning (Red Hat convention) |
|---|---|
| 0 | Halt — shut the system down |
| 1 (S) | Single-user mode — maintenance; root only, no networking |
| 2 | Multi-user without network services such as NFS (on Debian, 2–5 are all full multi-user) |
| 3 | Full multi-user, text console, with networking |
| 4 | Unused / user-definable |
| 5 | Multi-user with a graphical (X11) login |
| 6 | Reboot |
SysV init runs the scripts for the default runlevel (id:3:initdefault: in /etc/inittab): scripts live in /etc/init.d, and the directory /etc/rc.d/rc3.d holds symbolic links named S## (start, in numeric order) and K## (kill). runlevel prints the previous and current runlevel (e.g. N 5), who -r the current one, and init 3 or telinit 3 switches. Ubuntu used the event-driven Upstart from 2006 until 2014.
systemd (Lennart Poettering and Kay Sievers, 2010) is now the init system of almost all major distributions — Fedora from 2011, RHEL 7 from 2014, Debian 8 and Ubuntu 15.04 from 2015. It manages units (.service, .socket, .target, .mount, .timer, .device), starts them in parallel according to their dependencies, activates services on demand through sockets, tracks every process in a cgroup and logs to the journal. Runlevels become targets:
| SysV runlevel | systemd target |
|---|---|
| 0 | poweroff.target |
| 1 | rescue.target (emergency.target is even more minimal) |
| 2, 3, 4 | multi-user.target |
| 5 | graphical.target |
| 6 | reboot.target |
systemctl get-default # e.g. graphical.target
systemctl set-default multi-user.target # boot to text mode from now on
systemctl isolate rescue.target # switch now (like init 1)
systemctl status sshd # is the service running?
systemctl start sshd ; systemctl stop sshd
systemctl enable sshd # start automatically at boot
systemctl list-units --type=service
journalctl -b # log messages of the current boot
systemd-analyze blame # which units slowed the bootOnce the default target is reached, systemd starts getty (agetty) on each virtual console (tty1–tty6, reached with Ctrl+Alt+F1–F6) and on serial lines. getty prints /etc/issue and the login: prompt, reads a user name and runs login, which asks for the password and checks it through PAM against /etc/shadow. If /etc/nologin exists only root may log in. login then sets the UID, GID and groups, records the session in utmp/wtmp (used by who and last), shows /etc/motd, changes to the home directory and starts the login shell named in /etc/passwd. A login shell reads /etc/profile and then ~/.bash_profile or ~/.profile. Graphical systems use a display manager (GDM, LightDM, SDDM) instead; remote users arrive through sshd. The step-through diagram on this page traces the whole boot sequence.
shutdown -h now # halt and power off now
shutdown -r now # reboot now
shutdown -h +10 "Disk upgrade" # power off in 10 minutes, warning users
shutdown -r 23:30 # reboot at 23:30
shutdown -c # cancel a scheduled shutdown
poweroff ; reboot ; halt # immediate equivalents
init 0 ; init 6 # SysV style: halt, reboot
systemctl poweroff ; systemctl reboot ; systemctl suspendA clean shutdown broadcasts a warning to logged-in users (the wall mechanism), blocks new logins, sends SIGTERM to all processes and then SIGKILL to those that remain, flushes buffers (sync) and unmounts the file systems before halting or rebooting. Cutting the power instead loses buffered data and leaves file systems to be repaired. For recovery — a forgotten root password, a broken service — boot into single-user or rescue mode by adding single (SysV) or systemd.unit=rescue.target to the kernel line from the GRUB menu.
Every account has a user name and a numeric UID; every group has a GID. The kernel only ever compares numbers. UID 0 is root, the superuser, for whom permission checks are bypassed. System accounts for daemons (bin, daemon, mail, sshd, www-data) get low UIDs — 1–999 on RHEL 7+, Debian and Ubuntu (1–499 on RHEL 6 and older) — and usually the shell /sbin/nologin. Regular users start at 1000 (UID_MIN in /etc/login.defs). The account nobody is 65534.
| Field | Example value | Meaning |
|---|---|---|
| 1 | anita | Login name |
| 2 | x | Password placeholder — the real hash is in /etc/shadow |
| 3 | 1001 | UID |
| 4 | 1001 | Primary GID |
| 5 | Anita Nair,,, | GECOS / comment (full name, phone…) |
| 6 | /home/anita | Home directory |
| 7 | /bin/bash | Login shell |
/etc/passwd must be world-readable (mode 644) because many programs map names to UIDs, which is exactly why password hashes were moved to /etc/shadow, readable only by root. Each shadow line has 9 fields: name, hashed password, date of last change, minimum days between changes, maximum days the password is valid, warning days before expiry, inactive days allowed after expiry, account expiry date, and a reserved field. Dates are counted in days since 1 January 1970.
anita:$6$Kq3v…$Vb9…:20103:0:90:7:14:20908:
$6$ = SHA-512 hash ($1$ MD5, $5$ SHA-256, $y$ yescrypt; "!" or "*" = locked / no password login)
20103 = password last changed 15 Jan 2025 0 = may change again at once
90 = must change every 90 days 7 = warn 7 days before 14 = inactive grace days
20908 = account expires on 31 Mar 2027/etc/group has 4 fields — group name, password placeholder, GID and the comma-separated list of supplementary members, e.g. developers:x:1050:anita,ravi; group passwords and administrators live in /etc/gshadow. A user's primary group is field 4 of /etc/passwd. New accounts get copies of the template files in /etc/skel (.bashrc, .profile, .bash_logout) in their home directory, normally /home/username (root's is /root). Defaults come from /etc/login.defs and /etc/default/useradd.
useradd -m -s /bin/bash -c "Anita Nair" -G developers,sudo anita
passwd anita # set her password (run as root)
chage -d 0 anita # force a password change at first login
chage -M 90 -W 7 anita # password valid 90 days; warn 7 days before
chage -E 2027-03-31 anita # the account expires on this date
chage -l anita # list her password-ageing settings
usermod -aG docker anita # ADD a supplementary group (-a is essential)
usermod -s /bin/zsh anita # change the login shell
usermod -L anita # lock the account (passwd -l does the same)
userdel -r anita # delete the user, her home and mail spool
groupadd -g 1050 developers # create a group with GID 1050
gpasswd -a ravi developers # add ravi to the group (-d removes him)
id anita # uid=1001(anita) gid=1001(anita) groups=...
who # who is logged in; w also shows what they runusermod -G docker anita replaces all of Anita's supplementary groups with just docker — she silently loses sudo and developers. Always use usermod -aG to append. And useradd without -m may not create the home directory.useradd is the low-level program on every distribution: it creates a home directory only with -m (or if login.defs says CREATE_HOME yes) and sets no password. adduser on Debian/Ubuntu is a friendlier interactive script that creates the home directory, copies /etc/skel and asks for the password and full name; on RHEL and Fedora adduser is merely a link to useradd. passwd also locks (-l), unlocks (-u), expires (-e) and reports (-S) passwords.
su becomes root; su - ravi becomes ravisu - (or su -l) starts a login shell with the target's full environment; plain su keeps much of the caller'ssu -c 'command' runs one command; no per-command control or audit-u user)sudo -i gives a root login shell# who where = (as whom) what
root ALL = (ALL:ALL) ALL
%sudo ALL = (ALL:ALL) ALL # Debian/Ubuntu admin group (RHEL: %wheel)
ravi ALL = (root) NOPASSWD: /usr/bin/systemctl restart nginxls -l shows a file's metadata: -rwxr-x--- 1 anita developers 4096 Dec 3 10:15 report.sh — the file type (first character), nine permission characters for the owner (user), the group and others, the link count, owner, group, size, modification time and name. Type characters: - regular file, d directory, l symbolic link, c character device, b block device, p named pipe, s socket.
| Permission | On a file | On a directory |
|---|---|---|
| r (4) | Read the contents | List the names in it (ls) |
| w (2) | Modify the contents | Create, delete or rename entries in it |
| x (1) | Execute it as a program | Enter it (cd) and reach files inside it |
chmod 754 deploy.sh # rwxr-xr--
chmod u+x,g-w,o=r notes.txt # symbolic: add, remove, set exactly
chmod -R g+rX shared/ # recursively; X = execute only for directories (and files already executable)
chown anita:developers report # change owner and group
chgrp developers report # change group only
umask # show the mask, e.g. 0022
umask 027 # new files 640, new directories 750| Special bit | Octal | Shown as | Effect |
|---|---|---|---|
| setuid | 4000 | s in the owner's x position | The program runs with the file owner's privileges — /usr/bin/passwd is -rwsr-xr-x root, so any user can update /etc/shadow through it (Linux ignores setuid on scripts) |
| setgid | 2000 | s in the group's x position | On a program: runs with the file's group. On a directory: new files inherit the directory's group — ideal for shared project folders |
| sticky | 1000 | t in others' x position | On a directory: only a file's owner, the directory's owner or root may delete or rename it — /tmp is drwxrwxrwt (1777) |
-rwSr--r--). Convert any rwx string to octal and back in the Linux permissions (chmod) tool on this page.Try the problem first, then reveal the working one step at a time.
Interpret ravi:x:1002:1050:Ravi Kumar:/home/ravi:/bin/bash from /etc/passwd and ravi:!$6$Tz…:20103:1:60:7::: from /etc/shadow.
What permissions do new files and directories get with umask 022, 027, 077 and 033?
Give the octal mode and meaning of: (a) -rwxr-x--- (b) drwxrwxrwt (c) -rwsr-xr-x (d) drwxrwsr-x.
Account for every byte of the MBR, and show why an MBR disk cannot exceed 2 TiB with 512-byte sectors. How many primary partitions can it hold?
Write the commands to create user meera with a home directory, the bash shell, the comment “Meera K” and supplementary groups developers and sudo; set her password; force her to change it at first login; and make the account expire on 2027-06-30.
What permissions do new files and new directories get with umask 026? And with umask 002?
A team shares /srv/project. Explain what chmod 2775 /srv/project achieves, and what chmod 1777 /srv/upload adds. Why is setuid dangerous on a program owned by root?
On a systemd machine, how do you (a) see the default target, (b) make the machine boot to text mode permanently, (c) switch to rescue mode right now, and (d) do (c) the SysV way?
Put these boot steps in order and say what the firmware does if the first sector does not end in 0x55AA: kernel decompresses itself; getty shows login; POST; GRUB menu; systemd starts default.target; MBR loaded to 0x7C00; initramfs mounts the real root.
usermod -G replaces the supplementary-group list; usermod -aG appends to it.10 questions. 70 % passes the topic quiz (+30 XP, +20 more for 100 %). Exam scoring: +1 correct, −⅓ wrong.
Modelled on real KPSC questions (reworded) with the same concept and answer; each links to its original paper.