CompTIA Linux+ study materials
CompTIA Linux+ study resources

CompTIA Linux+ cheat sheet

CompTIA Linux+ · Keep the key ideas within reach.

Quick reference

System Management

  • uname -r prints the kernel release; hostnamectl displays or sets the static hostname, and timedatectl shows time zone and NTP status.

  • lsblk -f shows block devices with filesystem type, label, UUID, and mount point; blkid prints UUID and filesystem type for a device.

  • /etc/fstab fields are device/UUID, mount point, filesystem type, options, dump pass, and fsck pass; mount -a mounts entries not marked noauto.

  • df -h reports filesystem free and used space; du -sh /path totals apparent disk usage for a directory tree.

  • LVM creation order is pvcreate, vgcreate, then lvcreate; after lvextend, run resize2fs for ext4 or xfs_growfs for XFS.

  • tar -czf archive.tar.gz dir creates a gzip-compressed tar archive; tar -xzf extracts it; rsync -a preserves permissions, times, and symlinks.

  • systemctl daemon-reload reloads unit definitions; journalctl -b shows current-boot journal entries; dmesg shows the kernel ring buffer.

  • A systemd mount unit is named from its mount path, for example /data becomes data.mount; systemctl status data.mount checks it.

Quick reference

Services and User Management

  • systemctl enable unit creates boot-time symlinks; systemctl start unit starts it now; systemctl --failed lists failed units.

  • systemctl mask unit links the unit to /dev/null and prevents any start; systemctl unmask reverses it.

  • systemctl get-default shows the default target; multi-user.target is comparable to runlevel 3 and graphical.target to runlevel 5.

  • useradd -m -s /bin/bash user creates a home directory and login shell; usermod -aG group user adds a supplementary group without removing existing ones.

  • /etc/passwd has seven colon-separated fields: name, password placeholder, UID, GID, GECOS, home directory, and login shell.

  • /etc/shadow stores password hashes and aging data; chage -l user shows last change, minimum, maximum, warning, inactive, and expiry fields.

  • Cron format is minute, hour, day-of-month, month, day-of-week, command; /etc/crontab adds a user field before the command.

  • ss -tulnp lists listening TCP and UDP sockets with numeric ports and processes; loginctl list-sessions shows login sessions.

Quick reference

Security

  • Numeric permissions use read=4, write=2, execute=1; chmod 750 file gives owner rwx, group rx, and others no access.

  • umask 027 produces file mode 640 and directory mode 750 because the mask is subtracted from default modes 666 and 777.

  • Special permission bits are setuid=4, setgid=2, and sticky=1; find / -perm -4000 locates setuid files.

  • SELinux modes are enforcing, permissive, and disabled; getenforce shows the current mode and sestatus shows policy and mode.

  • SELinux file context changes use semanage fcontext -a -t type '/path(/.*)?' followed by restorecon -Rv /path.

  • ssh-keygen -t ed25519 creates an SSH key pair; the public key goes in ~/.ssh/authorized_keys; sshd_config controls PermitRootLogin and PasswordAuthentication.

  • Edit sudo rules with visudo; %wheel ALL=(ALL) ALL grants sudo to group wheel, and sudo -l lists allowed commands.

  • firewall-cmd --add-service=https changes runtime firewalld; add --permanent and run firewall-cmd --reload to persist it.

Quick reference

Automation, Orchestration, and Scripting

  • A script's first line #!/bin/bash is the shebang; the kernel uses it to select the interpreter for execution.

  • In shell, $? is the last exit status, $# is the argument count, and $@ expands to all positional arguments.

  • set -e exits on command failure; set -u errors on unset variables; set -x prints commands as they are executed.

  • Use [ -f file ] for file tests, -eq for numeric equality, and = for string equality; [[ ]] adds pattern matching in Bash.

  • $(command) captures standard output; command > file 2>&1 redirects both stdout and stderr to the same file.

  • Ansible playbooks are YAML task lists; ansible-playbook -i inventory site.yml runs them, and modules are designed to be idempotent.

  • sed -i 's/old/new/g' file edits in place; awk '{print $1}' prints the first whitespace-separated field.

Quick reference

Troubleshooting

  • systemctl status unit shows state and recent logs; journalctl -u unit -xe shows unit errors with explanations.

  • ip addr shows interface addresses, ip route shows routes, and ip route add default via GATEWAY sets the default gateway.

  • DNS checks include dig name, getent hosts name, and the nameserver entries in /etc/resolv.conf.

  • For disk-full issues, df -h checks filesystems, du -sh * checks directory usage, and lsof +L1 finds deleted files still held open.

  • fsck /dev/device must run on an unmounted filesystem; checking a mounted filesystem can cause corruption.

  • strace -p PID traces system calls, and lsof -p PID lists open files and sockets for a process.

  • namei -l /path/file prints permissions for each path component, locating where access is denied.