Published: Feb 23, 2025 by R. Vleeshouwers
Published: Feb 23, 2025 by R. Vleeshouwers
Linux system administration is a critical skill for any IT infrastructure and security implementation. This tutorial will guide you through the fundamental concepts and tools needed to manage Linux systems effectively, from basic command-line operations to essential administrative tasks. We’ll cover practical examples to help you understand how to apply these concepts in real-world scenarios.
The Linux file system follows a hierarchical structure starting from the root directory (/). Understanding this structure is essential for navigation and system administration. Key directories include:
The base of the filesystem hierarchy. All other directories branch from here.
User-specific storage areas. Each user has their own subdirectory under /home.
$ ls -l /home
drwx------ 2 john john 4096 Apr 15 10:30 john
drwx------ 2 jane jane 4096 Apr 15 10:30 jane
Contains all system-wide configuration files. Be careful when modifying these files, as incorrect changes can break your system.
$ ls /etc | head -10
apt
bash.bashrc
bind9
ca-certificates
cron.d
crontab
default
debootstrap
dpkg
group
Stores variable data such as logs, databases, and spool files. This directory often grows in size over time.
$ ls -la /var/log
total 40
drwxrwsr-x 7 root syslog 4096 Apr 15 10:30 .
drwxr-xr-x 13 root root 4096 Apr 15 10:30 ..
-rw-r--r-- 1 root root 12345 Apr 15 10:30 auth.log
-rw-r--r-- 1 root root 12345 Apr 15 10:30 syslog
-rw-r--r-- 1 root root 12345 Apr 15 10:30 messages
Contains user utilities and applications. Most software installed on your system goes here.
$ ls /usr/bin | grep vim
vim
vim.tiny
Contains essential command binaries needed for system recovery and booting. These are critical system files.
$ ls /bin | head -10
bash
cat
chgrp
chmod
chown
cp
date
dd
df
rm
Here are some fundamental commands every Linux administrator should know, along with practical examples and common flags. Mastering these commands will significantly boost your productivity in managing Linux systems.
lsThe ls command lists directory contents. It’s one of the most frequently used commands in Linux administration.
# Basic listing
$ ls
Desktop Documents Downloads Music Pictures Public Templates Videos
# List with details (long format)
$ ls -l
total 80
drwxr-xr-x 2 john john 4096 Apr 15 10:30 Desktop
drwxr-xr-x 2 john john 4096 Apr 15 10:30 Documents
drwxr-xr-x 2 john john 4096 Apr 15 10:30 Downloads
# List all files including hidden ones
$ ls -la
total 84
drwxr-xr-x 2 john john 4096 Apr 15 10:30 .
drwxr-xr-x 3 john john 4096 Apr 15 10:30 ..
-rw-r--r-- 1 john john 24 Apr 15 10:30 .bashrc
-rw-r--r-- 1 john john 24 Apr 15 10:30 .profile
# Sort by modification time (newest first)
$ ls -lt
total 80
drwxr-xr-x 2 john john 4096 Apr 15 11:15 Downloads
drwxr-xr-x 2 john john 4096 Apr 15 10:30 Desktop
drwxr-xr-x 2 john john 4096 Apr 15 10:30 Documents
cdThe cd command changes your current working directory. It’s essential for navigating the file system efficiently.
# Change to home directory
$ cd ~
$ pwd
/home/john
# Change to a specific directory
$ cd /etc
$ pwd
/etc
# Go back to previous directory
$ cd -
$ pwd
/home/john
# Go up one directory level
$ cd ..
$ pwd
/home
pwdThe pwd command prints the absolute path of your current directory, which is helpful for confirming your location in the filesystem.
$ pwd
/home/john/Documents/Projects
mkdirThe mkdir command creates new directories with various options for flexibility.
# Create a single directory
$ mkdir myproject
$ ls -l | grep myproject
drwxr-xr-x 2 john john 4096 Apr 15 11:15 myproject
# Create multiple directories at once
$ mkdir project1 project2 project3
# Create nested directories with -p flag
$ mkdir -p project/subdir1/subdir2
$ ls -R project
project:
subdir1
project/subdir1:
subdir2
rmThe rm command removes files and directories. Use it carefully, as removal is permanent without a recycle bin in Linux.
# Remove a file
$ rm myfile.txt
# Remove a directory and all its contents (-r for recursive)
$ rm -r mydirectory
# Remove a directory and all its contents with confirmation prompt
$ rm -ri mydirectory
# Remove files matching a pattern
$ rm *.tmp
cpThe cp command copies files and directories recursively with various options for controlling behavior.
# Copy a file
$ cp source.txt destination.txt
# Copy a directory recursively
$ cp -r sourcedir destinationdir
# Copy with verbose output showing progress
$ cp -v source.txt destination.txt
source.txt -> destination.txt
# Copy with preserving attributes (timestamps, ownership, etc.)
$ cp -p source.txt destination.txt
mvThe mv command moves files between directories or renames them, serving dual purposes for file management.
# Move a file to a different directory
$ mv myfile.txt /home/john/Documents/
# Rename a file
$ mv oldname.txt newname.txt
# Move multiple files to a directory
$ mv file1.txt file2.txt /home/john/Documents/
# Move a directory and its contents
$ mv myproject /home/john/Documents/
Managing users and groups is crucial in Linux administration. Linux systems can have multiple users with different levels of access and privileges. Understanding user management is essential for system security and proper access control.
Creating users involves more than just adding a username. Proper user management includes setting up appropriate permissions and configurations for different system roles.
# Create a new user with home directory and default shell (recommended method)
$ sudo adduser jane
Adding user `jane' ...
Adding new group `jane' (1001) ...
Adding new user `jane' (1001) with default shell `/bin/bash' ...
Creating home directory `/home/jane' ...
Copying files from `/etc/skel' ...
# Create a user without home directory (for system accounts)
$ sudo useradd -M -s /sbin/nologin www-data
# Add user to a group
$ sudo usermod -aG developers jane
# View user information
$ id jane
uid=1001(jane) gid=1001(jane) groups=1001(jane),1002(developers)
# Check if user exists
$ id jane 2>/dev/null || echo "User does not exist"
Groups allow administrators to manage permissions for multiple users simultaneously, simplifying access control management.
# Create a new group
$ sudo groupadd designers
# Add a user to a group
$ sudo usermod -aG designers jane
# Remove a user from a group
$ sudo gpasswd -d jane designers
# View group memberships for a user
$ groups jane
jane : jane developers designers
# List all groups on the system
$ cat /etc/group | grep -E "(developers|designers)"
developers:x:1002:
designers:x:1003:
Beyond basic creation, proper user account management includes setting passwords, configuring account expiration, and managing account lockout policies.
# Set or change password for a user
$ sudo passwd jane
New password: ********
Retype new password: ********
passwd: password updated successfully
# Lock a user account (prevents login)
$ sudo usermod -L jane
# Unlock a user account
$ sudo usermod -U jane
# Set account expiration date
$ sudo usermod -e 2026-12-31 jane
# Remove a user with home directory
$ sudo userdel -r jane
# View account information (including password aging)
$ chage -l jane
Last password change : Apr 15, 2026
Password expires : never
Password inactive : never
Account expires : never
Minimum number of days between password change : 0
Maximum number of days between password change : 99999
Number of days of warning before password expires : 7
Linux uses a permission system to control access to files and directories. Understanding file permissions is fundamental to Linux security and system administration. Each file and directory has three categories of permissions: owner, group, and others (world).
Each category can have one or more of these three permissions:
Permissions can be represented in two formats:
# Numeric (octal) format
$ ls -l file.txt
-rw-r--r-- 1 john john 1024 Apr 15 10:30 file.txt
# Symbolic format (first character indicates type, next three are owner, group, others)
# rwxrwxrwx = 777 (full permissions for all)
# rw-r--r-- = 644 (read/write for owner, read-only for group and others)
# rwx------ = 700 (read/write/execute for owner only)
chmodThe chmod command changes file permissions using either octal or symbolic notation.
# Using octal notation (each digit represents rwx for owner, group, others)
$ chmod 644 file.txt # Read/write for owner, read-only for group/others
$ chmod 755 script.sh # Read/write/execute for owner, read/execute for others
$ chmod 700 private.key # Read/write/execute for owner only
# Using symbolic notation (format: who|operation|permission)
$ chmod u+r file.txt # Add read permission for user (owner)
$ chmod g+w file.txt # Add write permission for group
$ chmod o-x file.txt # Remove execute permission for others
$ chmod a+r file.txt # Add read permission for all (user, group, others)
$ chmod u=rw,g=r,o=r file.txt # Explicit permission settings for each category
Here are common scenarios and their solutions:
# Securely store private keys (only owner should be able to read them)
$ chmod 600 private.key
# Set up public web content (readable by everyone, but writable by owner)
$ chmod 644 index.html
# Make a script executable
$ chmod 755 myscript.sh
# Create a private directory with restricted access
$ mkdir secure_dir
$ chmod 700 secure_dir
$ ls -ld secure_dir
drwx------ 2 john john 4096 Apr 15 11:15 secure_dir
Understanding how to manage processes is essential for Linux system administrators. Processes are running programs that consume system resources. Monitoring and controlling processes ensures optimal system performance and troubleshooting capability.
psThe ps command displays information about running processes.
# Show all processes in a simple format
$ ps aux | head -5
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 1 0.0 0.1 19400 1032 ? Ss Apr15 0:01 /sbin/init
root 2 0.0 0.0 0 0 ? S Apr15 0:00 [kthreadd]
# Show processes sorted by CPU usage
$ ps aux --sort=-%cpu | head -5
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
john 1234 5.2 0.5 45000 25000 pts/0 R+ 11:00 0:02 firefox
root 12 0.1 0.1 19400 1032 ? Ss Apr15 0:01 /sbin/init
...
# Show processes for a specific user
$ ps -u john
PID TTY TIME CMD
1234 pts/0 00:00:02 firefox
5678 pts/0 00:00:00 bash
top and htopTop and htop provide real-time views of system resources and running processes.
# Launch top (press 'q' to quit)
$ top
# Using htop (if installed)
$ htop
killThe kill command terminates processes by sending signals to them.
# Send SIGTERM signal (graceful termination)
$ kill 1234
# Send SIGKILL signal (forceful termination)
$ kill -9 1234
# Kill all processes with a specific name
$ pkill firefox
# Kill a process by name with confirmation
$ kill -9 $(pgrep firefox)
# List process IDs for a specific program
$ pgrep firefox
1234
Linux systems generate logs that are crucial for troubleshooting, security monitoring, and understanding system behavior. Log files provide detailed information about system events, user activities, and application behavior.
Key log files are stored in /var/log directory, each serving different purposes:
# System general messages
$ tail /var/log/messages
Apr 15 10:30:01 server systemd[1]: Started Session 1234 of user john.
Apr 15 10:30:02 server CRON[1235]: (john) CMD (/home/john/scripts/backup.sh)
# System logs
$ tail /var/log/syslog
Apr 15 10:30:01 server kernel: [12345.678901] usb 1-1: new high-speed USB device number 3 using ehci-pci
Apr 15 10:30:02 server sshd[1234]: Accepted password for john from 192.168.1.100 port 54321 ssh2
# Authentication logs
$ tail /var/log/auth.log
Apr 15 10:30:01 server sshd[1234]: Accepted password for john from 192.168.1.100 port 54321 ssh2
Apr 15 10:30:02 server CRON[1235]: (john) CMD (/home/john/scripts/backup.sh)
# Apache/Nginx logs (if installed)
$ tail /var/log/apache2/access.log
192.168.1.100 - - [15/Apr/2026:10:30:01 +0000] "GET / HTTP/1.1" 200 1234
192.168.1.101 - - [15/Apr/2026:10:30:02 +0000] "GET /favicon.ico HTTP/1.1" 404 123
Analyzing logs is essential for security monitoring and troubleshooting.
# View last 10 lines of a log file
$ tail -10 /var/log/syslog
# View first 10 lines of a log file
$ head -10 /var/log/syslog
# Search for specific entries in a log file
$ grep "error" /var/log/syslog
Apr 15 10:30:03 server kernel: [12345.678901] ERROR: Out of memory
# Show unique IP addresses from Apache logs
$ awk '{print $1}' /var/log/apache2/access.log | sort | uniq -c | sort -nr | head -5
# Count occurrences of a specific term in a log file
$ grep -c "failed" /var/log/auth.log
# Monitor log file changes in real-time
$ tail -f /var/log/syslog
In real-world Linux administration, you’ll often encounter typical scenarios that require combining multiple skills and commands.
When setting up a development environment for a team, you need to create shared directories, set appropriate permissions, and configure user access:
# Create a development directory
$ sudo mkdir -p /opt/projects/team1
# Set ownership to developers group
$ sudo chown -R root:developers /opt/projects/team1
# Set permissions for collaboration
$ sudo chmod -R 775 /opt/projects/team1
# Create individual user directories
$ sudo mkdir -p /home/john/project1
$ sudo mkdir -p /home/jane/project2
# Set proper ownership for user directories
$ sudo chown -R john:john /home/john/project1
$ sudo chown -R jane:jane /home/jane/project2
# Set restrictive permissions for private directories
$ sudo chmod 700 /home/john/project1
$ sudo chmod 700 /home/jane/project2
When system performance degrades, you can use various commands to diagnose the issue:
# Check system load
$ uptime
11:30:01 up 2:30, 2 users, load average: 1.50, 1.75, 1.80
# Check disk space usage
$ df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda1 20G 15G 4.5G 78% /
# Check memory usage
$ free -h
total used free shared buff/cache available
Mem: 7.8G 3.2G 2.1G 128M 2.5G 4.2G
# View top consuming processes
$ ps aux --sort=-%mem | head -5
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
john 1234 5.2 0.5 45000 25000 pts/0 R+ 11:00 0:02 firefox
Regular security checks help identify potential vulnerabilities and unauthorized access attempts:
# Check for recently modified files (last 24 hours)
$ find /home -type f -mtime -1
# Check for suspicious processes
$ ps aux | grep -v "grep" | grep -E "(ssh|telnet|ftp)"
# Check for unauthorized users
$ cat /etc/passwd | awk -F: '$3 > 1000 && $3 < 65534 {print $1}'
# Monitor SSH login attempts
$ grep "Accepted password" /var/log/auth.log
Mastering Linux system administration requires practice and understanding of core concepts. This tutorial has covered fundamental commands, user management, file permissions, process management, and system monitoring. The examples provided demonstrate how to apply these concepts in practical scenarios.
To become proficient in Linux administration, continue practicing with these commands, explore additional tools and documentation, and always remember to backup important configurations before making changes. Regular practice and exposure to real-world situations will help you develop expertise in managing Linux systems effectively. Start with basic commands and gradually work your way up to more complex administrative tasks. Regular practice and exploring documentation will help you become proficient in managing Linux systems effectively.
As you progress, consider learning advanced topics such as:
Share