<?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: Oyewumi David</title>
    <description>The latest articles on DEV Community by Oyewumi David (@seundavid_dev).</description>
    <link>https://dev.to/seundavid_dev</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%2F1720022%2Fac9100be-a797-479b-99f8-81b9f42d35e3.jpg</url>
      <title>DEV Community: Oyewumi David</title>
      <link>https://dev.to/seundavid_dev</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/seundavid_dev"/>
    <language>en</language>
    <item>
      <title>Creating Users and Groups on Linux with a Bash Script</title>
      <dc:creator>Oyewumi David</dc:creator>
      <pubDate>Tue, 02 Jul 2024 21:01:12 +0000</pubDate>
      <link>https://dev.to/seundavid_dev/creating-users-and-groups-on-linux-with-a-bash-script-3fm9</link>
      <guid>https://dev.to/seundavid_dev/creating-users-and-groups-on-linux-with-a-bash-script-3fm9</guid>
      <description>&lt;h2&gt;
  
  
  Overview
&lt;/h2&gt;

&lt;p&gt;This bash script automates the process of creating multiple users and groups on a Linux system. It's designed to streamline the onboarding process for new employees or system users. The script reads user information from an input file, creates users with their respective groups, sets random passwords, and logs all actions.&lt;/p&gt;

&lt;h2&gt;
  
  
  Features
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Creates users and their personal groups&lt;/li&gt;
&lt;li&gt;Adds users to additional specified groups&lt;/li&gt;
&lt;li&gt;Generates random passwords for each user&lt;/li&gt;
&lt;li&gt;Logs all actions for auditing purposes&lt;/li&gt;
&lt;li&gt;Stores generated passwords securely&lt;/li&gt;
&lt;li&gt;Handles existing users and groups&lt;/li&gt;
&lt;li&gt;Provides detailed error checking and reporting&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Prerequisites
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Linux environment (tested on Ubuntu)&lt;/li&gt;
&lt;li&gt;Root or sudo access&lt;/li&gt;
&lt;li&gt;Bash shell&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Installation
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Clone this repository &lt;code&gt;https://github.com/Seundavid18/HNG11-Stage-1-Task&lt;/code&gt; or download the &lt;code&gt;create_users.sh&lt;/code&gt; script.&lt;/li&gt;
&lt;li&gt;Make the script executable:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;   chmod +x create_users.sh
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Usage
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Create an input file (e.g., &lt;code&gt;users.txt&lt;/code&gt;) with the following format:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;   username; group1,group2,group3
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Each line represents a user. The username and groups are separated by a semicolon (;). Multiple groups are separated by commas (,).&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Run the script with root privileges:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;   sudo ./create_users.sh users.txt
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Replace &lt;code&gt;users.txt&lt;/code&gt; with the path to your input file.&lt;/p&gt;

&lt;h2&gt;
  
  
  Input File sample
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;light; sudo,dev,www-data
idimma; sudo
mayowa; dev,www-data
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Each line represents a user&lt;/li&gt;
&lt;li&gt;Username and groups are separated by a semicolon (;)&lt;/li&gt;
&lt;li&gt;Multiple groups are separated by commas (,)&lt;/li&gt;
&lt;li&gt;Whitespace around separators is ignored&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Output
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Users are created with their home directories&lt;/li&gt;
&lt;li&gt;Each user is assigned to their specified groups&lt;/li&gt;
&lt;li&gt;Random passwords are generated for each user&lt;/li&gt;
&lt;li&gt;All actions are logged in &lt;code&gt;/var/log/user_management.log&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Passwords are stored in &lt;code&gt;/var/secure/user_passwords.csv&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Troubleshooting
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Ensure you have root privileges when running the script&lt;/li&gt;
&lt;li&gt;Check the log file at &lt;code&gt;/var/log/user_management.log&lt;/code&gt; for detailed information about each action and any errors&lt;/li&gt;
&lt;li&gt;Verify that the input file is formatted correctly&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;By automating user and group management with a Bash script, you can efficiently handle multiple users, ensure security through proper permissions and password management, and maintain an audit log of all actions. This script provides a solid foundation for user management in a Linux environment.&lt;/p&gt;

&lt;h2&gt;
  
  
  HNG11 Interniship
&lt;/h2&gt;

&lt;p&gt;Visit &lt;a href="https://hng.tech/internship"&gt;https://hng.tech/internship&lt;/a&gt; | &lt;a href="https://hng.tech/hire"&gt;https://hng.tech/hire&lt;/a&gt; for more information about HNG and it's internship opportunities. &lt;/p&gt;

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