Unit 1: Linux Command Line and User Management

CSE493 — Linux System Administration 11 min read

I. Orientation — Linux Administration Through the Shell

Linux administration is centered on the shell: a text-based interface that interprets commands, starts programs, manipulates files, and controls users. Red Hat Enterprise Linux (RHEL) commonly uses Bash, the Bourne Again Shell, as the default interactive shell.

  • Command structure: Most commands follow command options arguments; in ls -l /etc, ls is the command, -l is an option, and /etc is an argument.
  • Case sensitivity: Linux distinguishes Report.txt, report.txt, and REPORT.txt.
  • Identity and permissions: Every process runs as a user and receives access according to user, group, and permission settings.
  • Filesystem model: Files and directories form one hierarchy beginning at the root directory /.
  • Administrative convention: Routine work should use an unprivileged account; elevated access is obtained only when required.
  • Prompt convention: $ commonly represents a regular-user prompt, while # represents a root prompt.

II. Command-Line Access — Starting and Controlling Shell Sessions

A. Accessing the command line

The command line provides direct access to programs through a shell prompt.

  • Terminal session: A terminal accepts keyboard input, displays output, and hosts a shell such as Bash.
  • Prompt information: A prompt like [student@server ~]$ identifies the user, host, current directory, and privilege level.
  • Remote access: Secure Shell connects to another Linux system:
    BASH
      ssh user@server.example.com
  • Session termination: exit or Ctrl+D closes the current shell.

B. Accessing command line using local console

A local console gives command-line access through hardware directly attached to the system or through a virtual-machine console.

  • Virtual consoles: RHEL provides text consoles that may be reached with combinations such as Ctrl+Alt+F3.
  • Authentication: The login: prompt requires a valid username and password.
  • Graphical return: The graphical session commonly occupies another virtual terminal, often reachable with Ctrl+Alt+F1 or Ctrl+Alt+F2.
  • Recovery value: Console access remains useful when networking or the graphical environment is unavailable.

C. Accessing command line using desktop

A desktop terminal emulator provides a shell inside the graphical environment.

  • Terminal application: GNOME Terminal opens an interactive shell without leaving the desktop session.
  • Multiple sessions: Tabs and windows can run independent shells under the same logged-in user.
  • Clipboard support: Desktop selection and clipboard features simplify transferring commands and output.
  • Security boundary: Opening a terminal does not automatically grant root privileges.

D. Executing commands using bash shell

Bash reads a command line, performs expansions and redirections, and then executes the resulting command.

  • Command history: history lists earlier commands; arrow keys recall them.
  • Completion: Tab completes commands and pathnames, reducing typing errors.
  • Command sequences: command1 ; command2 runs both, while command1 && command2 runs the second only after success.
  • Quoting: Single quotes preserve text literally; double quotes still permit variable expansion:
    BASH
      name="RHEL"
      echo "$name system"

III. File Management — Navigating and Manipulating the Hierarchy

A. Managing Files From the Command Line

File management begins with identifying the current location and navigating directories.

  • Current directory: pwd prints the absolute working-directory path.
  • Directory listing: ls -la includes hidden files and detailed metadata.
  • Navigation: cd /var/log uses an absolute path; cd .. moves to the parent.
  • Path types: Absolute paths begin with /; relative paths begin from the working directory.

B. The Linux File System Hierarchy

The Filesystem Hierarchy Standard organizes files by purpose under /.

  • System configuration: /etc contains host-specific configuration files.
  • User data: /home contains regular users’ home directories; /root is root’s home.
  • Programs and libraries: /usr stores most installed commands, libraries, and shared data.
  • Variable data: /var contains changing data such as logs, caches, and spool files.
  • Runtime and devices: /run stores runtime state, /dev exposes devices, and /proc presents process and kernel information.

C. Locating Files by Name

Linux provides indexed and real-time methods for finding files.

  • Real-time search: find walks directories and tests each entry:
    BASH
      find /etc -name '*.conf'
  • Case-insensitive search: find /home -iname 'report.txt' ignores letter case.
  • Database search: locate passwd searches a prebuilt filename database quickly.
  • Executable lookup: which ssh searches directories in $PATH; type cd also identifies shell built-ins.

D. Managing Files Using Command-Line Tools

Core utilities create, copy, move, and remove filesystem objects.

  • Creation: touch notes.txt creates an empty file; mkdir -p project/docs creates nested directories.
  • Copying: cp source.txt backup.txt copies a file; cp -r dir1 dir2 copies a directory tree.
  • Moving: mv old.txt new.txt renames a file or moves it elsewhere.
  • Removal: rm file removes a file, while rmdir emptydir removes only an empty directory.
  • Caution: rm -r recursively deletes content and normally provides no recovery facility.

E. Matching File Names Using Path Name Expansion

Pathname expansion, or globbing, lets Bash match multiple existing names with patterns.

  • Asterisk: *.txt matches names ending in .txt.
  • Question mark: file?.log matches exactly one character in the marked position.
  • Bracket expression: report[1-3] matches report1, report2, and report3.
  • Hidden files: A pattern must normally begin with . to match names beginning with a dot.
  • Shell responsibility: Bash expands the pattern before passing arguments to the command.

F. Managing Files with Shell Expansion

Shell expansions generate arguments, substitute values, and capture command output.

  • Brace expansion: mkdir chapter{1..3} generates three directory names.
  • Tilde expansion: ~/notes expands ~ to the current user’s home directory.
  • Variable expansion: echo "$HOME" prints the value of the HOME variable.
  • Command substitution: echo "Today is $(date +%F)" inserts command output.
  • Arithmetic expansion: echo $((6 * 7)) produces 42.

IV. Documentation and Support — Finding Authoritative Information

A. Getting Help in Red Hat Enterprise Linux

RHEL supplies layered help ranging from concise command syntax to installed manuals and vendor support.

  • Built-in help: help cd documents Bash built-ins.
  • Option summary: Many external commands support --help, as in useradd --help.
  • Command identification: type command determines whether a name is an alias, function, built-in, or executable.
  • Installed sources: Manual pages, Info documents, and package documentation remain available locally.

B. Reading Documentation Using man Command

The man command displays reference pages organized into numbered sections.

  • Common sections: Section 1 covers user commands, section 5 file formats, and section 8 administrative commands.
  • Explicit section: man 5 passwd opens documentation for /etc/passwd, rather than the passwd command.
  • Navigation: Space advances, /pattern searches, n repeats a search, and q quits.
  • Keyword lookup: man -k password searches manual-page names and descriptions.

C. Reading Documentation Using pinfo Command

pinfo is a text-based viewer for structured Info documentation.

  • Invocation: pinfo coreutils opens the Coreutils information tree.
  • Organization: Info documents use linked nodes rather than independent manual pages.
  • Navigation: Arrow keys select links, Enter follows a link, and q exits.
  • Fallback role: Info documentation may provide tutorials and detail beyond a command’s manual page.

D. Reading Documentation in /usr/share/doc

Installed packages commonly place supplementary documentation under /usr/share/doc.

  • Package directories: Content may include README, examples, release notes, licenses, and configuration samples.
  • Inspection: ls /usr/share/doc lists available package documentation.
  • Package ownership: rpm -qf /path/to/file identifies the package that installed a file.
  • Safe use: Examples should be reviewed and adapted before being applied to production configuration.

E. Getting Help From Red Hat

Red Hat provides support resources for systems covered by an appropriate subscription.

  • Customer Portal: The portal supplies product documentation, knowledge articles, downloads, and security information.
  • Support cases: Administrators can submit diagnostic details and track vendor-assisted investigations.
  • Diagnostics: sos report collects system configuration and logs into an archive for analysis.
  • Sensitive data: Diagnostic archives should be reviewed and transferred only through approved support channels.

V. Text Files and Data Flow — Creating, Editing, and Redirecting Content

A. Creating, Viewing, and Editing Text Files

Linux configuration and logs are commonly stored as plain text.

  • Creating content: touch file creates an empty file; printf '%s\n' "text" > file writes one line.
  • Viewing small files: cat file displays the complete contents.
  • Viewing long files: less file supports paging, searching, and backward movement.
  • Partial views: head shows the beginning and tail shows the end; tail -f /var/log/messages follows appended lines.

B. Redirecting Output to a File or Program

Redirection changes the destinations of standard input, standard output, and standard error.

  • File descriptors: Standard input is 0, output is 1, and error is 2.
  • Overwrite and append: > replaces a file’s content, while >> appends.
  • Error redirection: command 2> errors.log records error messages.
  • Combined output: command > all.log 2>&1 sends both output streams to one file.
  • Pipeline: journalctl | grep sshd sends one program’s output to another program’s input.

C. Editing Text Files from the Shell Prompt

Terminal editors permit direct modification of text without a graphical session.

  • Vim modes: vim file starts in Normal mode; i enters Insert mode and Esc returns to Normal mode.
  • Saving and exiting: :w writes, :q quits, and :wq performs both.
  • Simple alternative: nano file displays shortcut labels and uses commands such as Ctrl+O to write.
  • Administrative editing: sudoedit /etc/example.conf edits through controlled privilege handling.

D. Editing Text Files with a Graphical Editor

Graphical editors support mouse-driven editing within a desktop session.

  • Desktop tool: GNOME Text Editor can open ordinary text and configuration files.
  • Features: Search, replacement, syntax highlighting, and multiple tabs improve work on larger files.
  • Permissions: A graphical editor still obeys filesystem ownership and mode bits.
  • Operational caution: System files should be edited with suitable privileges and validated before restarting services.

VI. Local Identities — Users, Groups, Privileges, and Passwords

A. Managing Local Linux Users and Groups

Local account administration controls identities, resource ownership, and authorization on one host.

  • Account databases: /etc/passwd records user information; /etc/group records groups.
  • Protected credentials: Password hashes and aging data reside in /etc/shadow.
  • Numeric identity: The kernel primarily uses user IDs (UIDs) and group IDs (GIDs), not names.
  • Administrative tools: Commands such as useradd, usermod, groupadd, and passwd modify account databases.

B. Users and Groups

A user identifies an account, while groups collect users for shared access.

  • Primary group: Each user has one primary GID recorded in /etc/passwd.
  • Supplementary groups: Additional memberships grant access to group-owned resources.
  • Identity display: id alice shows Alice’s UID, primary GID, and group memberships.
  • Ownership display: ls -l reports the owning user and group for each file.

C. Gaining Superuser Access

Superuser access provides UID 0 privileges and must be tightly controlled.

  1. su method: su - starts a root login shell and normally requires the root password.
  2. sudo method: sudo command authorizes a permitted command using policy in /etc/sudoers and related files.
  • Policy editing: visudo checks syntax before installing sudoers changes.
  • Accountability: sudo supports per-user authorization and command logging.
  • Least privilege: Administrators should elevate only for commands requiring administrative access.

D. Managing Local User Accounts

User-management commands create, modify, lock, and remove accounts.

  • Creation: useradd -m alice creates Alice and, where configured, her home directory.
  • Modification: usermod -aG wheel alice adds Alice to wheel without replacing existing supplementary groups.
  • Locking: usermod -L alice locks password-based account authentication.
  • Deletion: userdel -r alice removes the account and its home directory; shared files elsewhere require separate review.
  • Defaults: /etc/login.defs and /etc/default/useradd influence account creation.

E. Managing Local Group Accounts

Group administration establishes shared identities for permission management.

  • Creation: groupadd developers creates a local group.
  • Membership: usermod -aG developers alice adds an existing user.
  • Modification: groupmod -n engineering developers renames the group.
  • Deletion: groupdel engineering removes the group entry but does not delete files carrying its numeric GID.
  • Verification: getent group developers displays the resolved group record.

F. Managing User Passwords

Password management includes setting credentials, locking authentication, and enforcing expiration.

  • Password setting: Root runs passwd alice; users run passwd to change their own password.
  • Status inspection: passwd -S alice reports password state and aging information.
  • Expiration policy: chage -M 90 -W 7 alice sets a 90-day maximum age and a seven-day warning.
  • Forced change: chage -d 0 alice requires a password change at the next login.
  • Locking and unlocking: passwd -l alice locks the password; passwd -u alice unlocks it.
  • Security scope: Locking a password does not necessarily terminate active sessions or disable non-password authentication such as existing SSH keys.