[go: up one dir, main page]

DEV Community

Vivesh
Vivesh

Posted on

Linux Administration Tasks 2

As a Linux administrator, managing systems effectively involves a variety of tasks, from automating jobs with Cron to securing applications. This guide walks you through 24 essential tasks with practical use cases and instructions.


1. Create a Cron Job

Cron automates repetitive tasks. Example: Schedule a backup every day at midnight.

Steps:

  1. Edit crontab:
   crontab -e
Enter fullscreen mode Exit fullscreen mode
  1. Add the job:
   0 0 * * * /path/to/backup.sh
Enter fullscreen mode Exit fullscreen mode
  1. Verify:
   crontab -l
Enter fullscreen mode Exit fullscreen mode

2. Linux Banner

Display a custom message on login using /etc/motd.

Steps:

  1. Edit /etc/motd:
   echo "Welcome to Linux Server" | sudo tee /etc/motd
Enter fullscreen mode Exit fullscreen mode

3. Linux Collaborative Directories

Set up a shared directory with proper permissions.

Steps:

  1. Create directory:
   mkdir /shared
Enter fullscreen mode Exit fullscreen mode
  1. Set group ownership and permissions:
   chgrp developers /shared
   chmod 2775 /shared
Enter fullscreen mode Exit fullscreen mode

4. Linux String Substitute (sed)

Modify files using sed. Example: Replace "error" with "warning".

Command:

sed -i 's/error/warning/g' logfile.txt
Enter fullscreen mode Exit fullscreen mode

5. Linux SSH Authentication

Set up key-based authentication for secure remote access.

Steps:

  1. Generate keys:
   ssh-keygen
Enter fullscreen mode Exit fullscreen mode
  1. Copy the public key to the server:
   ssh-copy-id user@server
Enter fullscreen mode Exit fullscreen mode

6. Linux Find Command

Locate files quickly. Example: Find .log files larger than 10MB.

Command:

find /path -type f -name "*.log" -size +10M
Enter fullscreen mode Exit fullscreen mode

7. Install a Package

Install htop as an example.

Command:

sudo apt install htop
Enter fullscreen mode Exit fullscreen mode

8. Install Ansible

Automate IT tasks with Ansible.

Steps:

  1. Install Ansible:
   sudo apt install ansible
Enter fullscreen mode Exit fullscreen mode
  1. Verify:
   ansible --version
Enter fullscreen mode Exit fullscreen mode

9. Configure Local Yum Repos

Set up a local YUM repository.

Steps:

  1. Create a repo file:
   sudo vi /etc/yum.repos.d/local.repo
Enter fullscreen mode Exit fullscreen mode
  1. Add content:
   [local-repo]
   name=Local Repository
   baseurl=file:///mnt/repo
   enabled=1
   gpgcheck=0
Enter fullscreen mode Exit fullscreen mode

10. Linux Services

Manage services. Example: Start and enable Apache.

Commands:

sudo systemctl start httpd
sudo systemctl enable httpd
Enter fullscreen mode Exit fullscreen mode

11. Linux Configure sudo

Grant sudo privileges.

Steps:

  1. Edit sudoers file:
   sudo visudo
Enter fullscreen mode Exit fullscreen mode
  1. Add user:
   username ALL=(ALL) NOPASSWD:ALL
Enter fullscreen mode Exit fullscreen mode

12. DNS Troubleshooting

Diagnose DNS issues.

Commands:

nslookup domain.com
dig domain.com
Enter fullscreen mode Exit fullscreen mode

13. Linux Firewalld Setup

Set up and manage firewalld.

Commands:

sudo firewall-cmd --add-port=80/tcp --permanent
sudo firewall-cmd --reload
Enter fullscreen mode Exit fullscreen mode

14. Linux Postfix Mail Server

Set up Postfix for email delivery.

Steps:

  1. Install:
   sudo apt install postfix
Enter fullscreen mode Exit fullscreen mode
  1. Configure via /etc/postfix/main.cf.

15. Linux Postfix Troubleshooting

Check logs:

sudo tail -f /var/log/mail.log
Enter fullscreen mode Exit fullscreen mode

16. Install and Configure HAProxy LBR

Load balance traffic with HAProxy.

Steps:

  1. Install HAProxy:
   sudo apt install haproxy
Enter fullscreen mode Exit fullscreen mode
  1. Configure /etc/haproxy/haproxy.cfg.

17. HAProxy LBR Troubleshooting

Check status:

sudo systemctl status haproxy
Enter fullscreen mode Exit fullscreen mode

Debug logs:

sudo journalctl -u haproxy
Enter fullscreen mode Exit fullscreen mode

18. MariaDB Troubleshooting

Check MariaDB logs:

sudo tail -f /var/log/mysql/error.log
Enter fullscreen mode Exit fullscreen mode

19. Linux Bash Scripts

Automate tasks. Example: Disk usage report.

#!/bin/bash
df -h > disk_report.txt
Enter fullscreen mode Exit fullscreen mode

20. Add Response Headers in Apache

Enhance security by adding headers.

Steps:

  1. Edit .htaccess or /etc/httpd/conf/httpd.conf:
   Header set X-Frame-Options "DENY"
Enter fullscreen mode Exit fullscreen mode
  1. Restart Apache:
   sudo systemctl restart httpd
Enter fullscreen mode Exit fullscreen mode

21. Apache Troubleshooting

Check configuration:

sudo apachectl configtest
Enter fullscreen mode Exit fullscreen mode

View logs:

sudo tail -f /var/log/httpd/error_log
Enter fullscreen mode Exit fullscreen mode

22. Linux GPG Encryption

Encrypt files with GPG.

Commands:

gpg --encrypt --recipient email@example.com file.txt
gpg --decrypt file.txt.gpg
Enter fullscreen mode Exit fullscreen mode

23. Linux Log Rotate

Automate log rotation.

Steps:

  1. Configure /etc/logrotate.conf.
  2. Test:
   logrotate -d /etc/logrotate.conf
Enter fullscreen mode Exit fullscreen mode

24. Application Security

Implement security measures like SELinux, AppArmor, or Fail2Ban.

Commands:

sudo apt install fail2ban
sudo systemctl enable fail2ban
Enter fullscreen mode Exit fullscreen mode

Happy Learning !!!

Top comments (0)