CompTIA Linux+ cheat sheet
CompTIA Linux+ · Keep the key ideas within reach.
System Management
uname -rprints the kernel release;hostnamectldisplays or sets the static hostname, andtimedatectlshows time zone and NTP status.lsblk -fshows block devices with filesystem type, label, UUID, and mount point;blkidprints UUID and filesystem type for a device./etc/fstabfields are device/UUID, mount point, filesystem type, options, dump pass, and fsck pass;mount -amounts entries not marked noauto.df -hreports filesystem free and used space;du -sh /pathtotals apparent disk usage for a directory tree.LVM creation order is
pvcreate,vgcreate, thenlvcreate; afterlvextend, runresize2fsfor ext4 orxfs_growfsfor XFS.tar -czf archive.tar.gz dircreates a gzip-compressed tar archive;tar -xzfextracts it;rsync -apreserves permissions, times, and symlinks.systemctl daemon-reloadreloads unit definitions;journalctl -bshows current-boot journal entries;dmesgshows the kernel ring buffer.A systemd mount unit is named from its mount path, for example
/databecomesdata.mount;systemctl status data.mountchecks it.
Services and User Management
systemctl enable unitcreates boot-time symlinks;systemctl start unitstarts it now;systemctl --failedlists failed units.systemctl mask unitlinks the unit to/dev/nulland prevents any start;systemctl unmaskreverses it.systemctl get-defaultshows the default target;multi-user.targetis comparable to runlevel 3 andgraphical.targetto runlevel 5.useradd -m -s /bin/bash usercreates a home directory and login shell;usermod -aG group useradds a supplementary group without removing existing ones./etc/passwdhas seven colon-separated fields: name, password placeholder, UID, GID, GECOS, home directory, and login shell./etc/shadowstores password hashes and aging data;chage -l usershows last change, minimum, maximum, warning, inactive, and expiry fields.Cron format is minute, hour, day-of-month, month, day-of-week, command;
/etc/crontabadds a user field before the command.ss -tulnplists listening TCP and UDP sockets with numeric ports and processes;loginctl list-sessionsshows login sessions.
Security
Numeric permissions use read=4, write=2, execute=1;
chmod 750 filegives owner rwx, group rx, and others no access.umask 027produces 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 -4000locates setuid files.SELinux modes are enforcing, permissive, and disabled;
getenforceshows the current mode andsestatusshows policy and mode.SELinux file context changes use
semanage fcontext -a -t type '/path(/.*)?'followed byrestorecon -Rv /path.ssh-keygen -t ed25519creates an SSH key pair; the public key goes in~/.ssh/authorized_keys;sshd_configcontrolsPermitRootLoginandPasswordAuthentication.Edit sudo rules with
visudo;%wheel ALL=(ALL) ALLgrants sudo to group wheel, andsudo -llists allowed commands.firewall-cmd --add-service=httpschanges runtime firewalld; add--permanentand runfirewall-cmd --reloadto persist it.
Automation, Orchestration, and Scripting
A script's first line
#!/bin/bashis 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 -eexits on command failure;set -uerrors on unset variables;set -xprints commands as they are executed.Use
[ -f file ]for file tests,-eqfor numeric equality, and=for string equality;[[ ]]adds pattern matching in Bash.$(command)captures standard output;command > file 2>&1redirects both stdout and stderr to the same file.Ansible playbooks are YAML task lists;
ansible-playbook -i inventory site.ymlruns them, and modules are designed to be idempotent.sed -i 's/old/new/g' fileedits in place;awk '{print $1}'prints the first whitespace-separated field.
Troubleshooting
systemctl status unitshows state and recent logs;journalctl -u unit -xeshows unit errors with explanations.ip addrshows interface addresses,ip routeshows routes, andip route add default via GATEWAYsets the default gateway.DNS checks include
dig name,getent hosts name, and the nameserver entries in/etc/resolv.conf.For disk-full issues,
df -hchecks filesystems,du -sh *checks directory usage, andlsof +L1finds deleted files still held open.fsck /dev/devicemust run on an unmounted filesystem; checking a mounted filesystem can cause corruption.strace -p PIDtraces system calls, andlsof -p PIDlists open files and sockets for a process.namei -l /path/fileprints permissions for each path component, locating where access is denied.