Basic Commands for Linux System Administration
Basic Commands for Linux System Administration
Linux is a powerful operating system widely used for servers, system administration, and development. Mastering its commands is essential for every system administrator. Here’s a quick guide to the most fundamental Linux commands for system administration.
1. User and Group Management
Managing users and groups is a key part of system administration.
Commands
adduser [username]
: Add a new user.sudo adduser john
passwd [username]
: Set or update a user password.sudo passwd john
usermod -aG [group] [username]
: Add a user to a group.sudo usermod -aG sudo john
deluser [username]
: Delete a user.sudo deluser john
2. File and Directory Management
Knowing how to navigate and manipulate files is crucial.
Commands
ls
: List files in a directory.ls -al
cd [directory]
: Change the current directory.cd /etc
cp [source] [destination]
: Copy files or directories.cp file.txt /home/user/
mv [source] [destination]
: Move or rename files.mv file.txt renamed_file.txt
rm [file/directory]
: Delete files or directories.rm -rf folder/
3. Disk and Filesystem Management
Monitoring and managing disk usage ensures optimal performance.
Commands
df -h
: Show disk space usage.df -h
du -sh [directory]
: Show directory size.du -sh /var/log
mount [device] [mountpoint]
: Mount a filesystem.sudo mount /dev/sda1 /mnt
umount [mountpoint]
: Unmount a filesystem.sudo umount /mnt
lsblk
: List information about block devices.lsblk
4. Process and System Monitoring
Monitoring system performance is vital for troubleshooting.
Commands
top
: Display active processes and resource usage.top
ps aux
: View details about running processes.ps aux
kill [PID]
: Terminate a process by PID.kill 1234
uptime
: Display how long the system has been running.uptime
5. Network Management
Network troubleshooting is essential for connectivity issues.
Commands
ip a
: Display IP address information.ip a
ping [hostname/IP]
: Test connectivity.ping google.com
netstat -tuln
: Show open ports and services.netstat -tuln
ss -tulwn
: Modern alternative to netstat.ss -tulwn
scp [source] [user@destination]:[path]
: Copy files securely between systems.scp file.txt user@remote:/home/user/
6. Service Management
Start, stop, and monitor services on the system.
Commands
systemctl start [service]
: Start a service.sudo systemctl start apache2
systemctl stop [service]
: Stop a service.sudo systemctl stop apache2
systemctl status [service]
: Check the status of a service.sudo systemctl status apache2
systemctl enable [service]
: Enable a service to start on boot.sudo systemctl enable apache2
systemctl disable [service]
: Disable a service from starting on boot.sudo systemctl disable apache2
7. Log Management
Logs provide critical insights into system activity.
Commands
cat /var/log/[logfile]
: View logs.cat /var/log/syslog
tail -f /var/log/[logfile]
: Monitor live logs.tail -f /var/log/syslog
journalctl -u [service]
: View logs for a specific service.journalctl -u apache2
Conclusion
Mastering these basic Linux commands will build a strong foundation for system administration. Regular practice will enhance your efficiency in managing systems.