<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Orisadare Damilola </title>
    <description>The latest articles on DEV Community by Orisadare Damilola  (@madeblaq).</description>
    <link>https://dev.to/madeblaq</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1719389%2F9df5efa2-e15a-4b24-8688-1a24c838c934.jpeg</url>
      <title>DEV Community: Orisadare Damilola </title>
      <link>https://dev.to/madeblaq</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/madeblaq"/>
    <language>en</language>
    <item>
      <title>Automating User Management on Linux with Bash Scripting</title>
      <dc:creator>Orisadare Damilola </dc:creator>
      <pubDate>Wed, 03 Jul 2024 08:01:39 +0000</pubDate>
      <link>https://dev.to/madeblaq/automating-user-management-on-linux-with-bash-scripting-1i6a</link>
      <guid>https://dev.to/madeblaq/automating-user-management-on-linux-with-bash-scripting-1i6a</guid>
      <description>&lt;p&gt;Managing user accounts and permissions on a Linux system is a fundamental task for system administrators and DevOps teams. Automating this process can streamline operations and ensure consistency across environments. In this guide, we'll walk through how to use a Bash script (create_users.sh) to automate user and group management efficiently.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Overview of create_users.sh&lt;/strong&gt;&lt;br&gt;
The &lt;code&gt;create_users.sh&lt;/code&gt; script is designed to read user and group information from an input file (input_file.txt), create user accounts with specified groups, generate secure passwords, and log all actions for audit purposes. This script is particularly useful in environments where user provisioning and access control need to be automated.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Prerequisites&lt;/strong&gt;&lt;br&gt;
Before you begin, ensure you have the following:&lt;/p&gt;

&lt;p&gt;Access to a Linux-based system (e.g., Ubuntu, CentOS)&lt;br&gt;
MobaXterm for SSH operations (optional for remote execution)&lt;br&gt;
Basic understanding of Bash scripting and command-line operations&lt;/p&gt;

&lt;p&gt;Step-by-Step Guide&lt;/p&gt;
&lt;h4&gt;
  
  
  1. Clone the repository
&lt;/h4&gt;

&lt;p&gt;first, clone the github repository containing the 'create_users.sh' script:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git clone https://github.com/Madeblaq/Bash-script.git
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  2. Prepare the Input File
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;subomi&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="nb"&gt;sudo&lt;/span&gt;,dev,www-data
chukwu&lt;span class="p"&gt;;&lt;/span&gt;dev,www-data
tolani&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="nb"&gt;sudo
&lt;/span&gt;hassan&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="nb"&gt;sudo&lt;/span&gt;,www-data
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  3. Upload Files to Your Linux System using Mobaxterm
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Open MobaXterm and connect to your Linux server via SSH.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Use the SFTP panel on the left side to upload &lt;code&gt;create_users.sh&lt;/code&gt; and &lt;code&gt;input_file.txt&lt;/code&gt; to your Linux server. Drag and drop the files into the desired directory.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  4. Convert Line Endings and Make the Script Executable
&lt;/h4&gt;

&lt;p&gt;Connect to your Linux server via SSH using MobaXterm and navigate to the directory where create_users.sh is located. Then, ensure proper line endings with dos2unix and make the script executable:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;apt-get &lt;span class="nb"&gt;install &lt;/span&gt;dos2unix
dos2unix create_users.sh
&lt;span class="nb"&gt;chmod&lt;/span&gt; +x create_users.sh
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  5. Execute the Script
&lt;/h4&gt;

&lt;p&gt;Run the &lt;code&gt;create_users.sh script&lt;/code&gt; with sudo to create users and groups based on &lt;code&gt;input_file.txt&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo&lt;/span&gt; ./create_users.sh input_file.txt
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  6. Verification
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Check the Log File:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo cat&lt;/span&gt; /var/log/user_management.log
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Check the Password File:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo cat&lt;/span&gt; /var/secure/user_passwords.txt
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Verify User Creation
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;grep&lt;/span&gt; &lt;span class="s1"&gt;'USERNAME'&lt;/span&gt; /etc/passwd
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Replace the 'USERNAME' with one of the usernames from the input file.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Check Group Membership
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;groups &lt;/span&gt;USERNAME
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h5&gt;
  
  
  7. Conclusion
&lt;/h5&gt;

&lt;p&gt;By leveraging &lt;code&gt;create_users.sh&lt;/code&gt;, you streamline user management tasks on your Linux system, enhancing operational efficiency and security. This script is not only a time-saver but also promotes consistency and accuracy in user provisioning, crucial for maintaining a well-managed IT infrastructure.&lt;/p&gt;

&lt;h5&gt;
  
  
  8. Learn More About HNG Internship
&lt;/h5&gt;

&lt;p&gt;This project is part of the &lt;a href="https://hng.tech"&gt;HNG Internship&lt;/a&gt;, aimed at developing practical skills in software development. Interested in hiring from the HNG Internship? Explore opportunities &lt;a href="https://hng.tech/hire"&gt;here&lt;/a&gt; or discover premium services &lt;a href="https://hng.tech/premium"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;This blog post provides a technical guide on setting up and using create_users.sh for automated user management on Linux. The step-by-step format and copyable code snippets make it easy to follow and implement. Adjust the paths and commands as per your specific setup, and feel free to enhance the content with visuals or additional technical insights as needed.&lt;/p&gt;

&lt;p&gt;Thank you for reading! If you have any questions or feedback, feel free to leave a comment below.&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
