The Self-Sufficiency Toolkit for a Linux Administrator
In the world of Linux, almost all system configuration is controlled by plain text files. The ability to find authoritative documentation for any command and to confidently edit these files from the shell prompt are the skills that separate a novice from a professional. This module covers the non-negotiable, foundational toolkit for becoming a self-sufficient system administrator.
Getting Help: `man`, `info`, and More
Linux is designed for professionals who learn by doing, and it provides extensive documentation directly on the command line. Knowing how to access this "offline internet" is the fastest way to solve problems.
Reading Manual Pages (`man`)
The man command is your first and most important resource. It provides the official system manual for commands, configuration files, and system calls.
CentOS Server Example: You need to know all the options for the firewall-cmd command to manage the firewall. You don't need Google; you need the man page.
$ man firewall-cmdNavigating `man` pages: Use the arrow keys to scroll, press / followed by a keyword (e.g., /--list-all) to search, n for the next match, and q to quit.
Using GNU Info (`info`)
The info pages are often more detailed than man pages, structured like a book with hyperlink-style "nodes." They are excellent for complex programs.
$ info tarThe `--help` Flag
For a quick reminder of a command's syntax and its most common options, the --help flag is often the fastest method.
$ dnf --helpI/O Redirection and Pipelines
This is the core philosophy of the Linux shell: every command is a small, specialized tool. Pipelines (|) and Redirection (>) are the techniques you use to chain these simple tools together to perform incredibly complex tasks.
Channels (File Descriptors) & Redirection
Every process has three standard channels: Standard Input (0), Standard Output (1), and Standard Error (2). Redirection allows you to control where these channels point.
>: Overwrites a file with Standard Output.>>: Appends Standard Output to a file.2>: Redirects Standard Error.&>: Redirects both Standard Output and Standard Error.
CentOS Server Example: Run a system update and save all output—both the package list and any errors—to a log file for later review.
$ sudo dnf update -y &> /tmp/update_log.txtPipelines (`|`) and `tee`
A pipeline takes the output of the command on its left and "pipes" it to become the input of the command on its right. The tee command allows you to send output to a file *and* still see it on the screen.
CentOS Server Super Example: Find the top 5 processes currently consuming the most memory, view the result on your screen, and save a copy for a report.
# ps aux lists all running processes
# sort -nk 4 sorts them numerically (-n) by the 4th column (memory %) in reverse (-r)
# head -n 5 shows only the top 5 lines
# tee saves a copy to a file
$ ps aux | sort -rnk 4 | head -n 5 | tee /tmp/top_5_mem_procs.txt
Editing Text Files with `vim`: The Administrator's Essential Tool
On a CentOS server, you will live in the command line, and nearly all system configuration is controlled by plain text files. `vim` (Vi IMproved) is a powerful, keyboard-driven text editor that is guaranteed to be present on virtually every Linux system you will ever encounter.
The source of `vim`'s power—and its steep learning curve—is that it is a modal editor. This means the keys on your keyboard perform different actions depending on which "mode" you are in. Instead of constantly moving your hand to the mouse or arrow keys, you can perform complex edits with maximum speed and efficiency directly from the home row.
The Four Modes of Operation
| Mode | Purpose | How to Enter / Exit |
|---|---|---|
| Command (Normal) Mode | Navigation, deleting, copying, and pasting. This is the default, "home base" mode. All powerful operations start from here. | Press Esc at any time from any other mode to return here. |
| Insert Mode | Typing and inserting text like a normal editor. You will see -- INSERT -- at the bottom of the screen. | From Command Mode, press i (insert before cursor) or a (append after cursor). |
| Extended Command (Ex) Mode | Saving, quitting, searching, replacing, and running advanced commands. | From Command Mode, press :. Your cursor will move to the command line at the bottom. |
| Visual Mode | Selecting blocks of text to copy, delete, or modify. | From Command Mode, press v for character selection or Shift+V for line selection. |
Vim Survival Skills: The Essential Commands
You don't need to learn all of `vim`'s commands at once. Master these essentials, and you can confidently edit any file on a CentOS server.
Saving & Quitting
These are all used from Extended Command Mode (start by typing :).
:w- write (save) the file.:q- quit the editor.:wq- write and quit (save and exit).:q!- quit without saving changes (force quit).
Navigation (in Command Mode)
The "home row" keys allow you to navigate without moving your hands.
h- leftj- downk- upl- rightG- Go to the last line of the file.gg- Go to the first line of the file.
Basic Editing (in Command Mode)
These commands let you manipulate text without entering Insert Mode.
x- delete the character under the cursor.dd- delete the entire current line.yy- yank (copy) the entire current line.p- paste the copied/deleted line below the cursor.u- undo the last action.
A critical security hardening step is to prevent the `root` user from logging in directly over SSH. This requires editing the SSH daemon's configuration file.
- Backup the file first! This is a crucial habit.
sudo cp /etc/ssh/sshd_config /etc/ssh/sshd_config.bak - Open the file with `vim`:
sudo vim /etc/ssh/sshd_config - Find the line: The file opens in Command Mode. To search, type
/PermitRootLoginand press Enter. Your cursor will jump to the correct line. - Enter Insert Mode: The line probably says
#PermitRootLogin yes. Use the arrow keys to move your cursor to the#. Pressxto delete the comment character. Move to the end of the line. Pressato enter Insert Mode and start appending text. Backspace over "yes" and type "no". The line should now readPermitRootLogin no. - Return to Command Mode: Press Esc.
- Save and Quit: Enter Extended Command Mode by typing :, then type
wqand press Enter. - Apply the change: For the new configuration to take effect, you must restart the SSH service:
sudo systemctl restart sshd
Test Your Skills: Practice Lab
This lab will test your ability to use the essential `vim` commands to create and edit a simple shell script.
- Create and open a new file named
hello.shwith the command:vim hello.sh - Enter Insert Mode and type the following three lines:
#!/bin/bash # This is my first script echo "Hello, CentOS World!" - Return to Command Mode.
- Navigate to the second line (the comment).
- Yank (copy) the entire line using
yy. - Move your cursor to the last line and paste the copied line below it using
p. - Your file now has a duplicate comment. With your cursor on one of the comment lines, delete it using
dd. - Undo the deletion by pressing
u. The line should reappear. - Save the file and quit using the
:wqcommand. - Back at the shell prompt, make the script executable:
chmod +x hello.sh - Run your script to see the output:
./hello.sh