DEV Community

Harsh Pandhe
Harsh Pandhe

Posted on

Day 05: System Administration Like a Pro

Welcome to the final day of our Linux series! Today, we’re stepping into the shoes of a Linux System Administrator. You’ll learn how to manage users, processes, and services like a seasoned pro. Ready to level up? Let’s dive in!


What is System Administration?

System administration is all about keeping a Linux system running smoothly. It involves managing users, monitoring processes, configuring services, and ensuring everything works together harmoniously. Think of it as being the conductor of a tech orchestra.
Image description


Managing Users and Groups

1. Add a New User

Add a user with the adduser command:

sudo adduser username
Enter fullscreen mode Exit fullscreen mode

Follow the prompts to set up a password and basic user info.

2. Delete a User

Remove a user with:

sudo deluser username
Enter fullscreen mode Exit fullscreen mode

For a clean slate, delete their home directory too:

sudo deluser --remove-home username
Enter fullscreen mode Exit fullscreen mode

3. Switch Users

Switch to another user with:

su - username
Enter fullscreen mode Exit fullscreen mode

4. Manage Groups

Add a user to a group:

sudo usermod -aG groupname username
Enter fullscreen mode Exit fullscreen mode

Example: Adding jane to the sudo group:

sudo usermod -aG sudo jane
Enter fullscreen mode Exit fullscreen mode

Monitoring and Managing Processes

Processes are the programs running on your system. Here’s how to keep an eye on them:

1. View Running Processes

Use top to see a live list of running processes:

top
Enter fullscreen mode Exit fullscreen mode

Exit with q.

Or, use ps for a snapshot:

ps aux
Enter fullscreen mode Exit fullscreen mode

2. Kill a Process

Terminate a misbehaving process with its PID (Process ID):

kill PID
Enter fullscreen mode Exit fullscreen mode

If it refuses to die, use:

kill -9 PID
Enter fullscreen mode Exit fullscreen mode

3. Monitor System Resources

Check memory and CPU usage:

free -h
Enter fullscreen mode Exit fullscreen mode
uptime
Enter fullscreen mode Exit fullscreen mode

Managing Services

Linux services (a.k.a. daemons) are background processes that handle tasks like web servers, databases, and more. Here’s how to manage them:

1. Start, Stop, and Restart Services

Control services with systemctl:

sudo systemctl start servicename
sudo systemctl stop servicename
sudo systemctl restart servicename
Enter fullscreen mode Exit fullscreen mode

Example: Restarting the Apache web server:

sudo systemctl restart apache2
Enter fullscreen mode Exit fullscreen mode

2. Check Service Status

See if a service is running:

sudo systemctl status servicename
Enter fullscreen mode Exit fullscreen mode

3. Enable and Disable Services

Enable a service to start on boot:

sudo systemctl enable servicename
Enter fullscreen mode Exit fullscreen mode

Disable it:

sudo systemctl disable servicename
Enter fullscreen mode Exit fullscreen mode

Scheduling Tasks with Cron

Automate repetitive tasks using Cron. Cron jobs are scheduled tasks defined in a special file called the crontab.

1. Edit the Crontab

Open the crontab editor:

crontab -e
Enter fullscreen mode Exit fullscreen mode

2. Add a Cron Job

Cron jobs follow this format:

minute hour day month day_of_week command
Enter fullscreen mode Exit fullscreen mode

Example: Run a backup script every day at 2 AM:

0 2 * * * /path/to/backup.sh
Enter fullscreen mode Exit fullscreen mode

3. List Cron Jobs

View your scheduled tasks:

crontab -l
Enter fullscreen mode Exit fullscreen mode

Backing Up Your System

Backups are a sysadmin’s best friend. Here’s a simple way to back up files and directories:

Using rsync

rsync -av /source/directory /backup/directory
Enter fullscreen mode Exit fullscreen mode

Example: Back up your home directory:

rsync -av /home/username /mnt/backup
Enter fullscreen mode Exit fullscreen mode

Tips and Best Practices

  • Keep Your System Updated: Use sudo apt update && sudo apt upgrade (or your distro’s equivalent) regularly.
  • Monitor Logs: Check logs for errors and anomalies. System logs are often in /var/log.
  • Limit Root Access: Use sudo instead of logging in as root.
  • Backup Regularly: Always have a backup plan.
  • Document Everything: Keep notes on what you configure for future reference.

Resources to Explore


Conclusion

Congratulations! You’ve completed the 5-day Linux journey. You’ve gone from learning what Linux is to mastering system administration. Whether you’re managing users, processes, or services, you now have the skills to navigate Linux like a pro.

Keep Learning

This is just the beginning. Linux is a vast and fascinating world. Keep exploring, practicing, and experimenting. The command line is your canvas—go create something amazing.

Top comments (0)