☑️Day 16: Practicing Shell Scripting and User Management in Red Hat🚀

🔹Table Of content :

  • ✅Introduction

  • ✅Writing Shell Scripts in Red Hat

  • ✅Adding New Users in RHEL via Script

  • ✅Editing Files Using Vim

  • ✅Basic Linux Commands for User Management & Permissions

    • whoami

    • chmod

    • ls -l

    • passwd

    • exit

  • ✅User Input for User Creation

  • ✅Key Takeaways from Day 16


Hey everyone! 👋

Today was Day 16 of my DevOps journey, and I focused on practicing shell scripts and diving deeper into user management in Red Hat Enterprise Linux (RHEL). It was a hands-on day where I learned to add users, manage files, and work with essential Linux commands. Here's a breakdown of what I covered:


🛠️ 1. Writing Shell Scripts in Red Hat

I started the day by practicing basic shell scripting. Writing scripts in Linux allows for powerful automation, making repetitive tasks much easier. I worked on a script that would add new users with a prompt for user input, which brings me to the next skill I honed today.


👤 2. Adding New Users in RHEL via Script

User management is a core task in system administration. I created a script that automates the process of adding users by accepting user input. Here’s a basic example of how it works:

#!/bin/bash
echo "Enter the username:"
read username
sudo useradd $username
echo "User $username has been added successfully!"

This simple script helps to automate adding users without manually typing commands for each one.


📝 3. Editing Files Using Vim

Working with Vim was another big part of today’s learning. It’s a powerful text editor, and mastering it is essential for editing configuration files or scripts. I practiced:

  • Editing files: Opening a file using vim filename.

  • Inserting text: Pressing i to enter insert mode.

  • Saving changes: Using :w to write the changes.

  • Exiting Vim: Using :q to quit, or :wq to save and quit.


🔒 4. Basic Linux Commands for User Management & Permissions

In addition to scripting and file editing, I practiced essential Linux commands related to user management and file permissions:

  • whoami: Displays the current logged-in user.
whoami
  • chmod: Changes file permissions.
chmod 755 filename

This command is crucial for ensuring that files and directories have the correct permissions for different users.

  • ls -l: Lists files with detailed information, including permissions.
ls -l
  • passwd: Changes a user’s password. As an admin, this is an important command to ensure user security.
passwd username
  • exit: Exits the current shell session.
exit

🔑 5. User Input for User Creation

In addition to scripting, I explored how to get user input for creating accounts. This allows for more interactive and dynamic scripts, which is incredibly helpful when working in real-world environments.

#!/bin/bash
echo "Enter the username:"
read username
sudo useradd $username
echo "Set password for $username:"
sudo passwd $username
echo "User $username has been added and password set!"

This script not only adds a new user but also prompts the admin to set the password, making it a streamlined process.


💡 Key Takeaways from Day 16:

  • Shell scripting is essential for automating user management tasks in Red Hat.

  • Vim is a powerful tool for editing scripts and system files.

  • Commands like whoami, chmod, ls -l, and passwd are essential in everyday Linux operations.

  • Combining scripting with user input adds flexibility to your scripts, making them more practical for real-world use.


I’m feeling more confident every day as I continue to practice these essential skills in RHEL. These tasks are fundamental for any Linux system administrator, and I can already see how valuable they’ll be in my future projects. 🚀

Stay tuned as I continue to dive deeper into DevOps and Red Hat in the coming days!

Happy Learning!😊

#90DaysOfDevOps

#RHEL #Linux #ShellScripting #UserManagement #DevOps #Vim #Automation #TechJourney #Day16

💡
Follow for more updates on LinkedIn , GitHub and Twitter(X)
14
Subscribe to my newsletter

Read articles from Kedar Pattanshetti directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Kedar Pattanshetti
Kedar Pattanshetti