DEV Community

Vivesh
Vivesh

Posted on

4

Linux Administration Tasks with Use Cases

Managing a Linux system effectively requires proficiency in a wide range of administrative tasks. Below is a guide to key tasks with examples and use cases to streamline operations and ensure security.


1. Custom Apache User Setup

Objective: Create a dedicated Apache user for running the web server securely.

Commands:

sudo useradd -r -d /var/www -s /sbin/nologin apache
sudo chown -R apache:apache /var/www
Enter fullscreen mode Exit fullscreen mode

Use Case: Secure a web server by running Apache as a non-privileged user.


2. Group Creation and User Assignment

Objective: Create a group for developers and assign users.

Commands:

sudo groupadd devteam
sudo usermod -aG devteam user1
Enter fullscreen mode Exit fullscreen mode

Use Case: Facilitate collaboration by giving group-level permissions to project files.


3. Linux User Setup with Non-Interactive Shell

Objective: Create a user with no interactive shell to limit login access.

Commands:

sudo useradd -s /sbin/nologin backupuser
Enter fullscreen mode Exit fullscreen mode

Use Case: Use for users who only require FTP or backup services.


4. Service User Creation without Home Directory

Objective: Add a service-specific user without a home directory.

Commands:

sudo useradd -M -r -s /bin/false serviceuser
Enter fullscreen mode Exit fullscreen mode

Use Case: Securely run background services or daemons.


5. Temporary User Setup with Expiry

Objective: Create a user account with an expiration date.

Commands:

sudo useradd -e 2024-12-31 tempuser
Enter fullscreen mode Exit fullscreen mode

Use Case: Allow temporary access for contractors or short-term projects.


6. Linux User Data Transfer

Objective: Transfer user data to another directory or server.

Commands:

sudo rsync -av /home/user1/ /backup/user1/
Enter fullscreen mode Exit fullscreen mode

Use Case: Backup or migrate user data during system upgrades.


7. Secure Root SSH Access

Objective: Restrict SSH access for root users.

Steps:

  1. Edit the SSH configuration file:
   sudo nano /etc/ssh/sshd_config
Enter fullscreen mode Exit fullscreen mode
  1. Disable root login:
   PermitRootLogin no
Enter fullscreen mode Exit fullscreen mode
  1. Restart SSH:
   sudo systemctl restart sshd
Enter fullscreen mode Exit fullscreen mode

Use Case: Prevent unauthorized root access to the server.


8. Data Backup for Developer

Objective: Schedule regular backups for developers.

Commands:

crontab -e
# Add the following line:
0 2 * * * tar -czf /backup/dev_backup_$(date +\%F).tar.gz /home/dev
Enter fullscreen mode Exit fullscreen mode

Use Case: Ensure developers' data is secure in case of accidental deletion.


9. Script Execution Permissions

Objective: Make a script executable.

Commands:

chmod +x script.sh
./script.sh
Enter fullscreen mode Exit fullscreen mode

Use Case: Run custom scripts for automation or system management.


10. File Permission Correction

Objective: Correct permissions for shared directories.

Commands:

sudo chmod -R 775 /shared_folder
sudo chown -R user:group /shared_folder
Enter fullscreen mode Exit fullscreen mode

Use Case: Prevent unauthorized access to sensitive shared files.


11. String Replacement

Objective: Replace strings in configuration files.

Commands:

sed -i 's/oldstring/newstring/g' config.txt
Enter fullscreen mode Exit fullscreen mode

Use Case: Update URLs, paths, or configurations programmatically.


12. Secure Data Transfer

Objective: Transfer data securely between servers.

Commands:

scp file.tar.gz user@remote:/path/to/destination
Enter fullscreen mode Exit fullscreen mode

Use Case: Migrate sensitive data between servers securely.


13. Restrict Cron Access

Objective: Restrict specific users from scheduling cron jobs.

Commands:

Add users to /etc/cron.deny:

echo "user1" | sudo tee -a /etc/cron.deny
Enter fullscreen mode Exit fullscreen mode

Use Case: Prevent misuse of system resources.


14. Default GUI Boot Configuration

Objective: Change default boot to GUI mode.

Commands:

sudo systemctl set-default graphical.target
sudo reboot
Enter fullscreen mode Exit fullscreen mode

Use Case: Enable a desktop environment for easier management.


15. Timezone Alignment

Objective: Set the correct timezone for the server.

Commands:

sudo timedatectl set-timezone Asia/Kolkata
Enter fullscreen mode Exit fullscreen mode

Use Case: Align logs and cron jobs with local time.


16. Firewall Configuration

Objective: Set up and enable a firewall.

Commands:

sudo ufw allow 22
sudo ufw enable
Enter fullscreen mode Exit fullscreen mode

Use Case: Secure the server by controlling network access.


17. Process Limit Adjustment

Objective: Modify user process limits.

Steps:

  1. Edit limits file:
   sudo nano /etc/security/limits.conf
Enter fullscreen mode Exit fullscreen mode
  1. Add or modify:
   user1 soft nproc 1024
Enter fullscreen mode Exit fullscreen mode

Use Case: Prevent resource exhaustion due to excessive processes.


18. SELinux Installation and Configuration

Objective: Enable SELinux for enhanced security.

Commands:

sudo apt install selinux
sudo setenforce 1
sudo sestatus
Enter fullscreen mode Exit fullscreen mode

Use Case: Enforce mandatory access controls on critical systems.


_By implementing these tasks, as a Linux administrators you can efficiently manage systems, ensure security, and optimize performance for varied use cases.

Happy Learning !!! _

Speedy emails, satisfied customers

Postmark Image

Are delayed transactional emails costing you user satisfaction? Postmark delivers your emails almost instantly, keeping your customers happy and connected.

Sign up

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Explore a sea of insights with this enlightening post, highly esteemed within the nurturing DEV Community. Coders of all stripes are invited to participate and contribute to our shared knowledge.

Expressing gratitude with a simple "thank you" can make a big impact. Leave your thanks in the comments!

On DEV, exchanging ideas smooths our way and strengthens our community bonds. Found this useful? A quick note of thanks to the author can mean a lot.

Okay