Unit 1: Linux Command Line and User Management
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; inls -l /etc,lsis the command,-lis an option, and/etcis an argument. - Case sensitivity: Linux distinguishes
Report.txt,report.txt, andREPORT.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:
BASHssh user@server.example.com - Session termination:
exitorCtrl+Dcloses 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+F1orCtrl+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:
historylists earlier commands; arrow keys recall them. - Completion:
Tabcompletes commands and pathnames, reducing typing errors. - Command sequences:
command1 ; command2runs both, whilecommand1 && command2runs the second only after success. - Quoting: Single quotes preserve text literally; double quotes still permit variable expansion:
BASHname="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:
pwdprints the absolute working-directory path. - Directory listing:
ls -laincludes hidden files and detailed metadata. - Navigation:
cd /var/loguses 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:
/etccontains host-specific configuration files. - User data:
/homecontains regular users’ home directories;/rootis root’s home. - Programs and libraries:
/usrstores most installed commands, libraries, and shared data. - Variable data:
/varcontains changing data such as logs, caches, and spool files. - Runtime and devices:
/runstores runtime state,/devexposes devices, and/procpresents process and kernel information.
C. Locating Files by Name
Linux provides indexed and real-time methods for finding files.
- Real-time search:
findwalks directories and tests each entry:
BASHfind /etc -name '*.conf' - Case-insensitive search:
find /home -iname 'report.txt'ignores letter case. - Database search:
locate passwdsearches a prebuilt filename database quickly. - Executable lookup:
which sshsearches directories in$PATH;type cdalso identifies shell built-ins.
D. Managing Files Using Command-Line Tools
Core utilities create, copy, move, and remove filesystem objects.
- Creation:
touch notes.txtcreates an empty file;mkdir -p project/docscreates nested directories. - Copying:
cp source.txt backup.txtcopies a file;cp -r dir1 dir2copies a directory tree. - Moving:
mv old.txt new.txtrenames a file or moves it elsewhere. - Removal:
rm fileremoves a file, whilermdir emptydirremoves only an empty directory. - Caution:
rm -rrecursively 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:
*.txtmatches names ending in.txt. - Question mark:
file?.logmatches exactly one character in the marked position. - Bracket expression:
report[1-3]matchesreport1,report2, andreport3. - 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:
~/notesexpands~to the current user’s home directory. - Variable expansion:
echo "$HOME"prints the value of theHOMEvariable. - Command substitution:
echo "Today is $(date +%F)"inserts command output. - Arithmetic expansion:
echo $((6 * 7))produces42.
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 cddocuments Bash built-ins. - Option summary: Many external commands support
--help, as inuseradd --help. - Command identification:
type commanddetermines 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 passwdopens documentation for/etc/passwd, rather than thepasswdcommand. - Navigation: Space advances,
/patternsearches,nrepeats a search, andqquits. - Keyword lookup:
man -k passwordsearches manual-page names and descriptions.
C. Reading Documentation Using pinfo Command
pinfo is a text-based viewer for structured Info documentation.
- Invocation:
pinfo coreutilsopens 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
qexits. - 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/doclists available package documentation. - Package ownership:
rpm -qf /path/to/fileidentifies 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 reportcollects 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 filecreates an empty file;printf '%s\n' "text" > filewrites one line. - Viewing small files:
cat filedisplays the complete contents. - Viewing long files:
less filesupports paging, searching, and backward movement. - Partial views:
headshows the beginning andtailshows the end;tail -f /var/log/messagesfollows 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 is1, and error is2. - Overwrite and append:
>replaces a file’s content, while>>appends. - Error redirection:
command 2> errors.logrecords error messages. - Combined output:
command > all.log 2>&1sends both output streams to one file. - Pipeline:
journalctl | grep sshdsends 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 filestarts in Normal mode;ienters Insert mode andEscreturns to Normal mode. - Saving and exiting:
:wwrites,:qquits, and:wqperforms both. - Simple alternative:
nano filedisplays shortcut labels and uses commands such asCtrl+Oto write. - Administrative editing:
sudoedit /etc/example.confedits 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/passwdrecords user information;/etc/grouprecords 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, andpasswdmodify 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 aliceshows Alice’s UID, primary GID, and group memberships. - Ownership display:
ls -lreports the owning user and group for each file.
C. Gaining Superuser Access
Superuser access provides UID 0 privileges and must be tightly controlled.
sumethod:su -starts a root login shell and normally requires the root password.sudomethod:sudo commandauthorizes a permitted command using policy in/etc/sudoersand related files.
- Policy editing:
visudochecks syntax before installing sudoers changes. - Accountability:
sudosupports 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 alicecreates Alice and, where configured, her home directory. - Modification:
usermod -aG wheel aliceadds Alice towheelwithout replacing existing supplementary groups. - Locking:
usermod -L alicelocks password-based account authentication. - Deletion:
userdel -r aliceremoves the account and its home directory; shared files elsewhere require separate review. - Defaults:
/etc/login.defsand/etc/default/useraddinfluence account creation.
E. Managing Local Group Accounts
Group administration establishes shared identities for permission management.
- Creation:
groupadd developerscreates a local group. - Membership:
usermod -aG developers aliceadds an existing user. - Modification:
groupmod -n engineering developersrenames the group. - Deletion:
groupdel engineeringremoves the group entry but does not delete files carrying its numeric GID. - Verification:
getent group developersdisplays 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 runpasswdto change their own password. - Status inspection:
passwd -S alicereports password state and aging information. - Expiration policy:
chage -M 90 -W 7 alicesets a 90-day maximum age and a seven-day warning. - Forced change:
chage -d 0 alicerequires a password change at the next login. - Locking and unlocking:
passwd -l alicelocks the password;passwd -u aliceunlocks it. - Security scope: Locking a password does not necessarily terminate active sessions or disable non-password authentication such as existing SSH keys.
Did this save you a night before the exam?
LPU Notes is free, and it stays free. Ads cover part of the server bill. The rest comes out of a student's own pocket: the domain, the storage, and keeping the site up through the weeks everyone needs it at once.
The payment button didn't load. An ad blocker or a filtered network is the usual reason. to try again.
Nothing here is ever locked, and nothing unlocks. Chip in only if it was worth it. What it pays for →