Day 6: Advanced Linux Shell Scripting for DevOps Engineers with User Management

Advanced shell scripting

Day 6 focuses on advanced shell scripting techniques specifically for DevOps engineers. The key topic is user management in Linux, which involves:

  • Automating the creation, deletion, and modification of user accounts.

  • Managing groups and permissions.

  • Setting up password policies, expiration, and sudo privileges.

  • Ensuring efficient user access control and security, which is vital for system administration in a DevOps environment.

The goal is to use shell scripting to automate these processes, allowing DevOps engineers to handle user management at scale in a consistent and secure manner.

Task 1: Create Directories Using Shell Script:

Write a bash script createDirectories.sh that, when executed with three arguments (directory name, start number of directories, and end number of directories), creates a specified number of directories with a dynamic directory name.

Example 1: When executed as ./createDirectories.sh day 1 90, it creates 90 directories as day1 day2 day3 ... day90.

Example 2: When executed as ./createDirectories.sh Movie 20 50, it creates 31 directories as Movie20 Movie21 Movie22 ... Movie50.

Solution:

Output:

Movie directory:

Task 2: Create a Script to Backup All Your Work:

Backups are an important part of a DevOps Engineer's day-to-day activities. The video in the references will help you understand how a DevOps Engineer takes backups (it can feel a bit difficult but keep trying, nothing is impossible).

Task 3: Read About Cron and Crontab to Automate the Backup Script:

Cron is the system's main scheduler for running jobs or tasks unattended. A command called crontab allows the user to submit, edit, or delete entries to cron. A crontab file is a user file that holds the scheduling information.

First crontab file:

Taks 4 : Read About User Management:

A user is an entity in a Linux operating system that can manipulate files and perform several other operations. Each user is assigned an ID that is unique within the system. IDs 0 to 999 are assigned to system users, and local user IDs start from 1000 onwards.

  • Create 2 users and display their usernames.

In this post, we explored Advanced Linux Shell Scripting with a focus on user management. From automating user creation, managing groups, setting password policies, to monitoring login activity, these scripts empower DevOps engineers to manage users and permissions efficiently. By automating these tasks, you'll ensure better security, consistency, and scalability in your environments. 💻🔒

🚀 Keep Going!

Mastering these scripting techniques will level up your DevOps game! The more you automate, the smoother your processes will run. Stay curious, keep scripting, and continue your journey toward becoming an expert in Linux for DevOps! ⚡💪