CertGrid CertGrid

Linux+ XK0-006 command cheat sheet

The commands the five XK0-006 domains actually need, in weight order, with output from the same captures the guides use. One Debian-family host and one RPM-family host, because the exam may hand you either.

Domain 1 - System Management (23%)

  • lsblk -o NAME,SIZE,TYPE,MOUNTPOINTS

    The first storage command on any unfamiliar machine: disks, partitions, LVM and mount points as a tree, changing nothing.

    Full guide
  • losetup -fP --show <file>

    Attach a file as a real block device. `-f` picks the first free one and prints it; `-P` asks the kernel to scan it for partitions.

    Full guide
  • mkfs.ext4 -L <label> <device> && blkid <device>

    Make a filesystem and read back the UUID it generated. The UUID belongs to the filesystem, so reformatting changes it.

    Full guide
  • findmnt --verify --verbose

    Check /etc/fstab BEFORE a reboot. It also warns when systemd is still using the old copy and needs `systemctl daemon-reload`.

    Full guide
  • systemd-analyze critical-chain

    What actually delayed the boot. `blame` sorts units by their own duration and lists things nothing waited for - this shows the chain.

    Full guide
  • dpkg -S $(command -v <prog>) / rpm -qf $(command -v <prog>)

    Which package owns a running program. The single most useful packaging query, and it is spelled differently on each family.

    Full guide

Domain 2 - Services and User Management (20%)

  • systemd-analyze verify <unit-file>

    Parse a unit before enabling it. Warnings about OTHER units on the machine are normal - read the exit status, not the volume.

    Full guide
  • systemctl show <unit> -p User -p Group -p ExecMainStatus

    The effective values after every drop-in, in machine-readable form. `ExecMainStatus` is the exit code the process last returned.

    Full guide
  • journalctl -u <unit> -n 20 --no-pager -o cat

    The second command in every service failure. `systemctl status` says it failed; this says why, because `-o cat` prints what the process itself wrote.

    Full guide
  • useradd -D / grep UID_MIN /etc/login.defs

    What the next account will look like before you create it. Note `SHELL=/bin/sh` is the default - pass `-s /bin/bash` for a human.

    Full guide
  • sudo -l -U <user>

    Audit what a user may run, as sudo will actually apply it, without becoming them. Includes anything inherited from a group.

    Full guide
  • visudo -c -f /etc/sudoers.d/<file>

    Validate a sudo rule before trusting it. It names the file, line and column - and a broken file makes every sudo on the machine noisy.

    Full guide

Domain 3 - Security (18%)

  • sestatus / getenforce

    SELinux state, policy and BOTH modes: the running one and the one in the config file, which can differ until a reboot.

    Full guide
  • ls -Z <file>

    The SELinux label, which is what policy is written about. The type - `passwd_file_t`, `httpd_sys_content_t` - is the part that decides access.

    Full guide
  • restorecon -v <file> (or -Rv <dir>)

    Set the label the policy says a path SHOULD have. Use this rather than `chcon`, which is undone by the next relabel.

    Full guide
  • aa-status

    AppArmor profiles loaded and how many are enforcing. Note the tools that CHANGE a profile ship separately, in `apparmor-utils`.

    Full guide
  • ssh-keygen -lf <key>

    The fingerprint - identical for both halves of a pair, because it is a hash of the public key. That is how you match a key to an authorized_keys line.

    Full guide
  • sshd -T | grep -E '^(permitrootlogin|passwordauthentication)'

    The EFFECTIVE ssh policy, with every include and drop-in resolved - which is not what the main config file appears to say.

    Full guide
  • openssl x509 -in <crt> -noout -subject -issuer -dates -ext subjectAltName

    Read a certificate. Subject equal to issuer means self-signed; modern clients check subjectAltName and ignore the Common Name entirely.

    Full guide

Domain 4 - Automation, Orchestration and Scripting (17%)

  • set -euo pipefail

    The three settings that stop a script reporting success after a failed command. Without them the exit status is the LAST command's.

    Full guide
  • set -o pipefail

    Measured on and off: `false | true` returns 1 with it and 0 without. Essential in anything shaped like `command | grep | awk`.

    Full guide
  • git status --short / git diff --stat

    `M` in the second column is modified-in-worktree, `??` is untracked. `git diff` shows what is NOT staged; `--staged` shows what is.

    Full guide
  • podman unshare cat /proc/self/uid_map

    The rootless mapping: container uid 0 is your own uid on the host, and the rest come from /etc/subuid. Also how you chown a volume a container wrote.

    Full guide
  • podman build -t <name>:<tag> .

    Build from a Containerfile. A locally built image is named under `localhost/`, which is how podman keeps it apart from a registry image.

    Full guide
  • podman history --format "{{.CreatedBy}} {{.Size}}" <image>

    What every instruction cost. RUN adds bytes; LABEL, USER, ENTRYPOINT and CMD are 0 B - which is the whole argument for ordering a Containerfile.

    Full guide
  • podman generate systemd --new --name <container>

    Generate a unit rather than writing one. `--new` creates the container at each start, and the generator gets TimeoutStopSec right.

    Full guide

Domain 5 - Troubleshooting (22%)

  • cat /proc/pressure/{cpu,memory,io}

    How much time was LOST waiting, which an average cannot tell you. `some` is any task stalled; `full` is everything stalled at once.

    Full guide
  • ps -eo pid,pcpu,comm --sort=-pcpu | head / top -bn1

    `ps` is scriptable and reports a lifetime average; `top -bn1` reports the last interval. They disagree on a spike, and both are right.

    Full guide
  • lsof +L1 <mountpoint>

    The fault people reboot for: `df` says full, `du` disagrees, and a deleted file is still held open. `+L1` lists exactly those.

    Full guide
  • ss -ltnp | grep <port>

    Read the bind address before blaming the firewall. `127.0.0.1:8099` can never be reached remotely; `0.0.0.0:8099` can.

    Full guide
  • namei -l /full/path/to/file

    Walks every component of a path and names the one that refused. A 644 file can be unreadable because a directory two levels up is 700.

    Full guide
  • journalctl -p err -b / systemctl --failed

    The two triage commands for a machine you have just been handed. Priorities nest, so `-p err` includes critical and above.

    Full guide
  • systemd-run --scope -p MemoryMax=64M -p MemorySwapMax=0 <cmd>

    Bound a process for real. `MemoryMax` alone lets it swap instead of dying - both properties are needed, and the kill is logged as `oom-kill`.

    Full guide