CentOS (Community Enterprise Operating System) is a Linux distribution that historically provided a free, community-supported, and functionally compatible alternative to Red Hat Enterprise Linux (RHEL). It was widely used for servers due to its stability, long-term support, and robustness.
While CentOS Linux (the traditional rebuild of RHEL) has ceased, it has been succeeded by **CentOS Stream**, which is an upstream development branch for RHEL. Despite this shift, understanding CentOS principles is crucial for anyone working with RHEL-based systems in enterprise environments.
It's important to clarify the relationship between these distributions:
CentOS (or CentOS Stream) is primarily used as a server OS, but can also be installed with a GUI for desktop use or learning.
The command-line interface (CLI) is fundamental for managing CentOS. Open a "Terminal" application (if using GUI) or log in via SSH (if headless server).
pwd
ls -l # Long format (details)
ls -a # Show hidden files
ls -lh # Human-readable sizes
cd /etc
cd ~ # Home directory
mkdir my_new_folder
mkdir -p /opt/my_app/configs
rmdir empty_dir
touch document.txt
cp source.txt destination.txt
cp -r my_dir /tmp/
mv old_name.txt new_name.txt
mv file.txt /archive/
rm unwanted.txt
rm -rf my_dangerous_folder # Force remove recursively (EXTREME CAUTION!)
cat /etc/os-release # Show OS information
less /var/log/messages
tail -f /var/log/audit/audit.log # Follow a log file in real-time
echo "Hello, CentOS!"
man dnf
sudo dnf update # Update package lists
CentOS adheres to the Filesystem Hierarchy Standard (FHS), which defines a standardized directory structure for Linux systems.
Linux security relies heavily on file permissions and ownership to control access.
ls -l my_script.sh
# Example Output: -rwxr-xr-- 1 user group 1234 Jul 19 10:00 my_script.sh
Can use symbolic mode or octal (numeric) mode.
chmod 755 my_script.sh # Owner: rwx, Group: r-x, Others: r-x (-rwxr-xr-x)
chmod 644 my_document.txt # Owner: rw-, Group: r--, Others: r-- (-rw-r--r--)
chmod 700 my_private_key.pem # Only owner has full access
chmod u+x my_script.sh # Add execute permission for owner
chmod go-w my_document.txt # Remove write for group and others
Requires `sudo`.
sudo chown newuser:newgroup /opt/app/config.conf
sudo chgrp webadmin /var/www/html/index.html
CentOS, like other Linux systems, supports multi-user environments.
sudo adduser newuser
sudo passwd newuser # Set password for newuser
sudo useradd -m -s /bin/bash newuser2 # Create home dir, set Bash shell
sudo usermod -aG wheel newuser # Add newuser to 'wheel' group (grants sudo privileges on CentOS)
sudo usermod -l new_name old_name # Change username
sudo userdel newuser # Delete user, leave home directory
sudo userdel -r newuser2 # Delete user and remove home directory
sudo groupadd webdevs
sudo groupdel oldgroup
sudo gpasswd -a newuser webdevs # Add newuser to webdevs group
sudo gpasswd -d olduser webdevs # Remove olduser from webdevs group
CentOS (and RHEL-based systems) uses the RPM Package Manager, with `dnf` (Dandified YUM) being the modern front-end for installing, updating, and removing software packages. Older CentOS 7 and earlier used `yum`.
sudo dnf check-update # Check for available updates
sudo dnf update # Updates all installed packages
sudo dnf install httpd # Install Apache HTTP Server
sudo dnf install git nano vim # Install multiple packages
sudo dnf remove httpd
sudo dnf erase httpd # Same as remove
dnf search php
dnf info httpd
dnf list installed
dnf list available
sudo dnf group list # List available groups
sudo dnf groupinstall "Development Tools" # Install a group of related packages
sudo dnf autoremove
sudo dnf clean all
Managing running programs and tasks on your system.
ps aux # Show all running processes (user, CPU, memory)
ps -ef # Show all processes in full format
ps -p <PID> # Show info for a specific Process ID
top
htop
kill <PID> # Sends SIGTERM (graceful termination request)
kill -9 <PID> # Sends SIGKILL (forceful termination, cannot be ignored)
pkill firefox # Kills all processes named firefox
killall nginx # Kills all processes named nginx
CentOS (and other RHEL-based systems) uses `systemd` to manage system services (daemons) and boot processes.
systemctl status httpd.service # Check Apache status
# Output shows Active: (running), Loaded: (enabled/disabled), etc.
sudo systemctl start httpd.service
sudo systemctl stop httpd.service
sudo systemctl restart httpd.service
sudo systemctl enable httpd.service
sudo systemctl disable httpd.service
sudo systemctl reload httpd.service
CentOS uses `NetworkManager` or `systemd-networkd` for network configuration. Configuration files are typically in `/etc/sysconfig/network-scripts/`.
ip a # Shows interfaces like lo, eth0, ens33, etc.
ip route show
ping google.com
ss -tulnp # Show TCP/UDP listening ports with process info
nmcli device status # Show network device status
nmcli connection show # Show active network connections
nmcli device wifi list # Scan for Wi-Fi networks
nmcli device wifi connect "SSID" password "PASSWD" # Connect to Wi-Fi
sudo systemctl status firewalld # Check firewall status
sudo systemctl start firewalld # Start firewall
sudo systemctl enable firewalld # Enable firewall on boot
sudo firewall-cmd --permanent --add-service=http # Allow HTTP traffic permanently
sudo firewall-cmd --reload # Apply changes
# Example ifcfg-eth0 for static IP:
# Use 'sudo nano /etc/sysconfig/network-scripts/ifcfg-eth0' or 'sudo vi /etc/sysconfig/network-scripts/ifcfg-eth0'
# DEVICE=eth0
# BOOTPROTO=static
# ONBOOT=yes
# IPADDR=192.168.1.100
# NETMASK=255.255.255.0
# GATEWAY=1992.168.1.1
# DNS1=8.8.8.8
# DNS2=8.8.4.4
# After editing:
# sudo systemctl restart NetworkManager # Or network.service on older versions
Managing disk space, partitions, and file systems on CentOS.
df -h # Human-readable output
du -sh /var/log # Summarize size of /var/log
lsblk
sudo fdisk /dev/sda # Interactive partitioning tool
sudo mkfs.xfs /dev/sdb1 # Format partition sdb1 with XFS (common on CentOS)
sudo mount /dev/sdb1 /mnt/data # Mount sdb1 to /mnt/data
sudo umount /mnt/data # Unmount
# Basic LVM commands (conceptual):
sudo pvcreate /dev/sdb1 # Create Physical Volume
sudo vgcreate myvg /dev/sdb1 # Create Volume Group
sudo lvcreate -L 10G -n mylv myvg # Create Logical Volume
sudo mkfs.xfs /dev/myvg/mylv # Format LV
sudo mount /dev/myvg/mylv /data # Mount LV
Automate tasks by writing a series of commands in a file.
# Create a file named 'hello_centos.sh'
nano hello_centos.sh
# Add the following content:
#!/bin/bash
# This is a basic CentOS shell script
echo "Hello from CentOS!"
echo "Current date and time: $(date)"
echo "Disk usage of /home: $(df -h /home | awk 'NR==2{print $5}')"
chmod +x hello_centos.sh
./hello_centos.sh
You'll frequently use command-line text editors in CentOS, especially for configuration files.
nano /etc/nginx/nginx.conf
vim /etc/ssh/sshd_config
CentOS integrates robust security features. Proper configuration is key.
sudo dnf update -y
sestatus
sudo setenforce 0 # Switch to Permissive
sudo setenforce 1 # Switch to Enforcing
sudo nano /etc/selinux/config
# Change SELINUX=enforcing to SELINUX=permissive or SELINUX=disabled
# Reboot after changing this file for permanent effect.
sudo ausearch -c 'httpd' --raw | audit2allow -M mywebserver
sudo semodule -i mywebserver.pp # Create and apply custom SELinux policy
journalctl -f # Follow all logs
journalctl -u sshd.service # View SSH service logs
If you installed CentOS Stream as "Server with GUI", it comes with the GNOME desktop environment. If you installed a minimal version and want to add a GUI:
sudo dnf update -y
sudo dnf groupinstall "Server with GUI" -y
sudo systemctl set-default graphical.target
sudo reboot
sudo dnf install epel-release -y
sudo dnf --enablerepo=epel group install "Xfce" -y
echo "exec /usr/bin/xfce4-session" >> ~/.xinitrc
sudo systemctl set-default graphical.target
startx # Or reboot
CentOS (and its successor CentOS Stream) provides a robust, stable, and secure foundation for server environments. Mastering its command-line tools, package management, service control, and security features like Firewalld and SELinux is crucial for any system administrator or DevOps professional. Practice regularly in a VM or cloud environment to solidify your skills.