Back to exam

102-500 Cheatsheet

LPIC-1 Linux Administrator - Exam 102

Download free PDF

Shells and shell scripting

Bash startup files

  • **Login shells** read /etc/profile, then the first readable file among ~/.bash_profile, ~/.bash_login and ~/.profile. User startup files can explicitly source ~/.bashrc.
  • **Interactive non-login Bash** reads ~/.bashrc. System-wide Bash rc file names vary by distribution; /etc/profile is the standard system login initialization file.
  • **Sourced files** run in the current shell and need valid shell syntax and read access. They do not require execute permission or a shebang.
  • **Shebang** lines such as #!/bin/bash select an interpreter when an executable script is launched directly. Running bash script.sh explicitly selects Bash instead.

Variables, aliases and status

  • **Assignment** has no spaces around =: name=value. Use export NAME=value or export NAME to pass a variable to subsequently launched child processes.
  • **set** lists Bash variables and functions; **env** and **printenv** show the environment. A child cannot export a change back into its parent shell.
  • **alias** lists current aliases. Define or replace one with alias ll='ls -l'; remove it with unalias ll. Store persistent interactive aliases in ~/.bashrc.
  • **$** identifies the shell process; **$?** is the previous command's exit status, with zero conventionally meaning success. **$!** is the most recent asynchronous command's PID.
  • **Command substitution** captures output: mydate="$(date)". Double quotes preserve spaces; single quotes prevent expansion. **$((expression))** performs integer arithmetic.

Tests, input and iteration

  • **test** or [ expression ] checks conditions. Use -f for a regular file, -d for a directory and -z for an empty string; integer comparisons include -eq and -lt.
  • **if**, **for** and **while** use command exit status for control flow. Separate [ and ] from their arguments, and quote variable expansions in tests.
  • **read a b c** splits input using IFS; the last variable receives the remaining fields. For literal whole lines, use IFS= read -r line.
  • **seq LAST** starts at 1. **seq FIRST INCREMENT LAST** generates a stepped sequence up to the bound; it does not necessarily include LAST.
  • **Pipelines** connect output to input. In Bash, pipeline components commonly run in subshells, so changes inside a piped while loop may not survive afterward.

User interfaces and desktops

X11 displays and sessions

  • **X server** manages display and input devices; X clients are applications. **DISPLAY** selects the server using [host]:display[.screen], such as :0 or localhost:10.0.
  • **xorg.conf** uses Section "Name" through EndSection blocks. Configuration commonly lives in /etc/X11/xorg.conf and /etc/X11/xorg.conf.d/ snippets.
  • **Display managers**, such as XDM, GDM, KDM or SDDM, provide graphical authentication and launch the selected user session or desktop.
  • **SSH X11 forwarding** with ssh -X sets remote DISPLAY automatically and tunnels application traffic. The application runs remotely while its interface appears locally.

Remote graphics and accessibility

  • **SPICE** supports remote interaction with a virtual machine's graphical console and can redirect local USB devices when the client and guest support it.
  • **Screen readers** turn interface text and structure into speech or Braille output. **Refreshable Braille displays** present characters using movable physical dots.
  • **Accessibility aids** also include magnification, high contrast, on-screen keyboards, sticky keys and slow keys. Choose the aid for the user's visual or motor needs.

Administrative tasks

Account databases and identity

  • **/etc/passwd** fields are name, password marker, UID, primary GID, GECOS, home and shell. The marker **x** normally indicates a password hash stored in /etc/shadow.
  • **/etc/shadow** restricts access to password hashes and records aging fields, including the last password-change day. It does not store SSH private keys or the last login time.
  • **/etc/group** records group name, password field, GID and supplementary member list. Primary membership comes from the GID in /etc/passwd and need not appear in that list.
  • **UIDs and GIDs** occupy separate namespaces; the same numeric value can identify both a user and a group without a conflict.
  • **getent passwd** queries configured name-service sources for account entries; **getent group** queries groups. **id USER** shows a user's UID and group memberships.

Creating and restricting accounts

  • **useradd -m** creates a home directory and copies skeleton files, normally from /etc/skel. **-d** sets the home path, **-u** the UID, **-g** the primary group and **-s** the shell.
  • **usermod -aG GROUP USER** appends supplementary membership. Omitting -a when using -G replaces the supplementary group list. New login sessions pick up membership changes.
  • **passwd** manages passwords; **chage** manages password aging and account expiration. **chage -l USER** displays aging information.
  • **nologin** or **/bin/false** as a login shell blocks a normal interactive shell. The presence of **/etc/nologin** conventionally blocks non-root logins through participating login services.

Recurring jobs with cron

  • **User crontab** entries contain minute, hour, day of month, month, day of week, then command. **/etc/crontab** and /etc/cron.d files add a username before the command.
  • **Ranges**, lists and steps select schedule values: * means every value, 1-5 is a range, and */10 is a step. Standard five-field cron has no year field.
  • **crontab -e** edits the current user's table; **-l** lists it and **-r** removes it. Jobs receive a limited environment; set PATH or use absolute command paths.
  • **/etc/cron.allow**, when present, lists permitted users. Otherwise /etc/cron.deny excludes listed users. Behavior when both are absent depends on the cron implementation and system policy.

One-time jobs and systemd timers

  • **at** schedules one-time jobs for atd; **atq** lists queued jobs and **atrm JOB** removes one. at.allow takes precedence over at.deny; an allow file limits access to listed users.
  • **/etc/at.deny** excludes listed users when /etc/at.allow is absent. Removing a username from an allow file can also revoke scheduling access.
  • **Timer units** have a [Timer] section with triggers such as OnCalendar= or OnBootSec=. By default, a timer activates the service with the same base name; Unit= can select another unit.
  • **systemctl list-timers** shows active timers; --all includes inactive ones. Timers can run in system or user scope; use systemctl --user for the latter.

Locales and character encoding

  • **LANG** supplies the default locale; category variables such as **LC_MESSAGES** and **LC_TIME** specialize messages and time formatting. **LC_ALL**, when set, overrides category settings and LANG.
  • **Locale names** must correspond to installed locales, commonly language_TERRITORY.encoding. **locale** shows current settings and **locale -a** lists available locales.
  • **/etc/locale.conf** stores system locale defaults on systems that use it, such as LANG and LC_TIME. Use LC_ALL as a temporary environment override rather than a persistent setting there.
  • **iconv -f FROM -t TO** converts character encodings. It changes byte representation, not the language of the text.

Essential system services

System time, hardware clock and zones

  • **date** displays or, with suitable privileges, sets system time. Formatting strings control output; a time zone changes local presentation of Unix timestamps.
  • **/etc/localtime** is a copy of or symlink to a compiled zoneinfo file under /usr/share/zoneinfo. **timedatectl set-timezone AREA/CITY** selects a zone on systemd systems.
  • **hwclock --systohc** writes system time to the hardware clock; **hwclock --hctosys** sets system time from the hardware clock. Keep the direction distinct.
  • **NTP** disciplines system time against reference sources. chrony and ntpd use **server** for a source and **pool** for a source pool; **iburst** speeds initial synchronization with a short burst of requests.

The systemd journal

  • **systemd-journald** collects service, kernel and application messages with metadata such as _PID and _UID. It supports syslog facility and priority information and can coexist with syslog.
  • **journalctl -u UNIT** filters a unit; **--since** and **--until** constrain time. **-b** selects a boot, **-p** a priority range and **-f** follows new entries.
  • **/run/log/journal/** holds volatile journal data; **/var/log/journal/** holds persistent data when enabled. Storage policy is configured in journald.conf or its drop-ins.
  • **logger MESSAGE** submits a syslog message. **systemd-cat COMMAND** connects a command's output to the journal. Forwarding to another logging daemon depends on configuration.

Syslog routing and log rotation

  • **Syslog selectors** use facility.priority. Facilities include kern, user, auth, mail and local0 through local7; priorities run from emerg through alert, crit, err, warning, notice, info and debug.
  • **mail.*** selects every mail priority; **mail.crit** selects critical and more severe mail messages. **With traditional selectors**, *.crit applies the threshold across facilities.
  • **Traditional remote actions** use @HOST for UDP forwarding; rsyslog also supports @@HOST for TCP. File actions use a pathname; exact configuration syntax depends on the logging daemon.
  • **logrotate** rotates logs and can compress, retain or mail old logs. Policies normally live in /etc/logrotate.conf and /etc/logrotate.d/; postrotate actions can ask daemons to reopen files.

Mail submission, queues and aliases

  • **MTAs** transfer mail using SMTP. Postfix and Exim commonly provide a **sendmail-compatible** submission command; the command name does not prove the Sendmail MTA is installed.
  • **mailq** lists queued mail; **sendmail -bp** is a compatible queue-listing form. A queued message is awaiting processing or delivery, not evidence of successful delivery.
  • **Aliases** map local recipients to destinations. Edit the configured aliases file, commonly /etc/aliases or /etc/mail/aliases, then run **newaliases** to rebuild its lookup database.
  • **~/.forward** can redirect a user's incoming mail where supported by the MTA. An **open relay** accepts unauthorized third-party SMTP forwarding and invites abuse.

CUPS printing

  • **/etc/cups/** holds CUPS configuration. **cupsd.conf** configures the scheduler; **printers.conf** stores printer definitions. Prefer supported CUPS tools for printer changes.
  • **lp** and **lpr** submit print jobs. **lpq** shows a queue; **lpstat -o** lists jobs and **lpstat -p** reports printer status.
  • **cancel** or **lprm** removes jobs. Distinguish managing an existing job from enabling a printer or allowing its queue to accept new work.

Networking fundamentals

IPv4 subnets and IPv6

  • **CIDR /n** gives the network-prefix length. A conventional IPv4 subnet has 2^(32-n) addresses; reserving network and broadcast leaves two fewer host addresses. /31 links and /32 routes are special cases.
  • **Subnet boundaries** follow the mask, not decimal appearance. Determine the network and broadcast first; usable host addresses lie between them in a conventional subnet.
  • **Private IPv4** ranges are 10.0.0.0/8, 172.16.0.0/12 and 192.168.0.0/16. **127.0.0.0/8** is loopback; **169.254.0.0/16** is link-local.
  • **IPv6** has eight hexadecimal 16-bit groups. Leading zeroes may be omitted; one **::** can compress a run of zero groups. Two separate :: compressions make an address ambiguous.
  • **IPv6 has no broadcast**; it uses multicast and unicast mechanisms. Routers decrement **Hop Limit**, preventing indefinite forwarding loops. TCP and UDP remain transport protocols.

Interfaces and NetworkManager

  • **ip link set dev eth0 up** enables the link; down disables it. **ip addr show** displays addresses; ip addr add ADDRESS/PREFIX dev DEVICE adds an address.
  • **ip -s link show eth0** reports receive/transmit counters. **ifconfig eth0** provides legacy interface status and counters where net-tools is installed.
  • **ifup** and **ifdown** apply configured interface settings on systems that provide them. Files such as /etc/network/interfaces and ifcfg-* belong to particular distribution mechanisms.
  • **nmcli device** manages devices; **nmcli connection** manages profiles. Profiles can represent Ethernet, Wi-Fi or bridges. **nmtui** provides a terminal text interface.
  • **nmcli device wifi connect SSID** connects to a Wi-Fi network and can create a profile. **nmcli networking connectivity check** can report none, portal, limited, full or unknown. Which interfaces NetworkManager manages depends on its configuration and plugins.

Routing and network diagnostics

  • **ip route show** displays routes. The kernel prefers the **longest matching prefix**; metrics distinguish otherwise comparable routes. A default route is used when no more-specific route matches.
  • **ip route del default** removes a default route; legacy **route del default** performs the corresponding operation. Multiple tables or matching routes may require additional selectors.
  • **ip route get ADDRESS** shows the selected path. A directly connected route transmits on its interface; a gateway route forwards through the specified next hop.
  • **ping** normally sends ICMP Echo Requests and waits for replies. Failure can reflect filtering as well as a down host. Check link state, address, route and name resolution separately.
  • **netstat** can show sockets, routes and interface statistics using different options. **ss** inspects sockets; **lsof -i** associates network sockets with processes when permissions allow. Numeric options such as route -n avoid name-lookup delays.

Hostnames, DNS and service ports

  • **hostname** displays or temporarily sets the host name. **hostnamectl set-hostname NAME** manages a persistent host name on systemd systems.
  • **/etc/nsswitch.conf** controls lookup sources and ordering. **hosts: files dns** normally tries /etc/hosts before DNS, subject to any configured status-action rules.
  • **/etc/resolv.conf** uses **nameserver** for resolver addresses and **search** for suffixes. Network managers or resolver services may generate this file; configure the owning service for lasting changes.
  • **dig** displays DNS query details and responses. Query types include A for IPv4, AAAA for IPv6, MX for mail exchangers, NS for name servers and SOA for zone authority metadata.
  • **HTTPS** conventionally uses TCP 443; HTTP uses 80, SSH 22 and SMTP 25. **/etc/services** maps service names to port/protocol pairs; it does not start or stop services.

Security

Privileges and resource limits

  • **sudoers** rules describe user, host, run-as identity and permitted commands. Edit with **visudo** for syntax checking; **sudo -l** lists allowed commands.
  • **NOPASSWD:** suppresses authentication for following commands until another tag changes it. **PASSWD:** restores authentication; sudo normally asks for the invoking user's password, subject to policy.
  • **ulimit** controls shell resource limits inherited by child processes. Soft limits are current bounds; hard limits cap unprivileged increases. **ulimit -a** lists limits; **ulimit -c** controls core-file size.
  • **ulimit -v** limits virtual address space where supported; it is not a direct resident-RAM quota. PAM limits can apply session limits through /etc/security/limits.conf and limits.d.
  • **SetUID** executables run with the file owner's effective UID. **find / -type f -user root -perm -4000** locates root-owned regular files with that bit; inspect elevated programs deliberately.

SSH server and user identities

  • **Host keys** identify SSH servers. Clients record trusted host keys in **known_hosts**; verify an unexpected change through a trusted channel before accepting it.
  • **User key pairs** authenticate users. Keep the private key secret on the client; place the public key in the target account's **~/.ssh/authorized_keys**. Multiple public keys can authorize one account.
  • **ssh-keygen** creates key pairs. **ssh -i KEYFILE USER@HOST** selects an identity file. A passphrase protects a private key at rest.
  • **/etc/ssh/ssh_config** supplies client defaults and **~/.ssh/config** user preferences. **/etc/ssh/sshd_config** configures the server daemon; client and server options have different roles.

SSH agents and key loading

  • **ssh-agent** holds identities and performs authentication signing operations for clients. **ssh-add** loads private keys into a running agent; it is separate from creating a key pair.
  • **SSH_AUTH_SOCK** names the agent's Unix-domain socket. Clients use it to communicate with the agent; the agent is not normally a TCP service on a fixed port.
  • **ssh-add -l** lists loaded key fingerprints; **ssh-add -D** removes all loaded identities. Protect agent access and enable forwarding only when the remote host is trusted.

Network service access controls

  • **xinetd** starts configured services on demand. Global configuration is normally /etc/xinetd.conf with service snippets under /etc/xinetd.d/; **disable = yes** disables a configured service.
  • **TCP wrappers** restrict access for services built with libwrap or launched through tcpd. /etc/hosts.allow is checked first, then /etc/hosts.deny; otherwise access is allowed.
  • **Wrapper rule changes** normally apply to new connection checks without a separate tcpd daemon restart. Existing connections remain established; services without wrapper support are unaffected.
  • **Reduce exposure** by disabling unnecessary services and checking listening sockets with ss -lntup. Wrapper rules, service configuration and packet filtering are separate control points.