<?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: horlatayorr</title>
    <description>The latest articles on DEV Community by horlatayorr (@horlatayorr).</description>
    <link>https://dev.to/horlatayorr</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%2F1056876%2F3bcd7908-d893-4fcc-8193-3f8055649325.png</url>
      <title>DEV Community: horlatayorr</title>
      <link>https://dev.to/horlatayorr</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/horlatayorr"/>
    <language>en</language>
    <item>
      <title>Managing User Accounts and Groups in Linux</title>
      <dc:creator>horlatayorr</dc:creator>
      <pubDate>Tue, 02 Jul 2024 01:41:10 +0000</pubDate>
      <link>https://dev.to/horlatayorr/managing-user-accounts-and-groups-in-linux-42g8</link>
      <guid>https://dev.to/horlatayorr/managing-user-accounts-and-groups-in-linux-42g8</guid>
      <description>&lt;p&gt;System AdministrationIn the realm of system administration, managing user accounts and groups is a fundamental task. This article delves into a Bash script designed to automate the creation of user accounts and their association with specific groups, a common requirement in dynamic environments such as software development teams. The script not only streamlines the setup process but also ensures security practices by generating random passwords for each user.&lt;/p&gt;

&lt;p&gt;The Script at a Glance&lt;br&gt;
&lt;a href="https://github.com/horlatayorr/HNG-Internship_Stage1.git"&gt;Link to code repository&lt;/a&gt;: &lt;br&gt;
This Bash script reads a text file containing usernames and group names, creates the users and groups, sets up home directories with appropriate permissions, generates random passwords, logs all actions to a log file, and stores the generated passwords securely.&lt;br&gt;
Step-By-Step Explanation&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Input Validation and Set Up&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvuu2opx93z72ecytdcda.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvuu2opx93z72ecytdcda.PNG" alt="Image description" width="711" height="421"&gt;&lt;/a&gt;&lt;br&gt;
The script begins by checking if an input file is provided and sets up necessary directories and files.&lt;br&gt;
Explanation:&lt;/p&gt;

&lt;p&gt;-Checks if the input file is provided as an argument.&lt;br&gt;
-Defines variables for the input file, log file, and password file.&lt;br&gt;
-Creates necessary directories and files with appropriate permissions.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Helper Functions
Defines helper functions for logging messages and generating random passwords.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fn6dqwg4yz5ayeazw1qwb.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fn6dqwg4yz5ayeazw1qwb.PNG" alt="Image description" width="702" height="372"&gt;&lt;/a&gt;&lt;br&gt;
Explanation:&lt;br&gt;
-log_message: Logs messages with a timestamp to the log file.&lt;br&gt;
-generate_password: Generates a random password using urandom.&lt;br&gt;
-Backs up the existing log and password files before making any changes.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Processing the Input File
Reads the input file line by line, extracting usernames and groups, and processes each user.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fssnq5tzwh037h9b1d49d.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fssnq5tzwh037h9b1d49d.PNG" alt="Image description" width="709" height="399"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1d0wp64ca6uk1iln1570.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1d0wp64ca6uk1iln1570.PNG" alt="Image description" width="711" height="408"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Explanation:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Reads the input file line by line, trimming whitespace.&lt;/li&gt;
&lt;li&gt;Skips empty or malformed lines.&lt;/li&gt;
&lt;li&gt;Checks if the user already exists and logs a message if they do.&lt;/li&gt;
&lt;li&gt;Creates a personal group and the user if they do not already exist.&lt;/li&gt;
&lt;li&gt;Sets appropriate permissions for the user’s home directory.&lt;/li&gt;
&lt;li&gt;Password Generation
Generates and sets a random password for the user, then stores it securely.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F297n87t72c7qnckstxx2.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F297n87t72c7qnckstxx2.PNG" alt="Image description" width="709" height="321"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Explanation:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Generates a random password for the user.&lt;/li&gt;
&lt;li&gt;Sets the generated password for the user.&lt;/li&gt;
&lt;li&gt;Stores the username and password securely in the password file.&lt;/li&gt;
&lt;/ul&gt;

&lt;ol&gt;
&lt;li&gt;Group Management
Adds the user to specified groups, creating any groups that do not already exist.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Explanation:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Checks if groups are specified for the user.&lt;/li&gt;
&lt;li&gt;Splits the groups by comma and processes each group.&lt;/li&gt;
&lt;li&gt;Creates the group if it does not already exist.&lt;/li&gt;
&lt;li&gt;Adds the user to the group and log
s the action.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Testing the Script&lt;br&gt;
To test the script, create a sample input file and execute the script:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Create the Sample Input File:&lt;br&gt;
&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgjpfnyib9hvg2xgu6l9k.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgjpfnyib9hvg2xgu6l9k.PNG" alt="Image description" width="678" height="168"&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Run the script.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F441yfgoivexokrgtcauv.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F441yfgoivexokrgtcauv.PNG" alt="Image description" width="677" height="81"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Check Outputs&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbulo60v4di00zpjiopcx.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbulo60v4di00zpjiopcx.PNG" alt="Image description" width="645" height="175"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Log File: Review /var/log/user_management.log for detailed logs.&lt;/li&gt;
&lt;li&gt;Password File: Verify /var/secure/user_passwords.txt for generated passwords.&lt;/li&gt;
&lt;li&gt;User Groups: Check the groups for each user using the id command:&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Conclusion&lt;br&gt;
By following this guide, you can effectively manage users and groups on your system, enhancing both efficiency and security.&lt;br&gt;
For those interested in further enhancing their skills or exploring opportunities in software development and system administration, the &lt;a href="https://hng.tech/internship"&gt;HNG Internship&lt;/a&gt; offers a comprehensive platform to learn, grow, and connect with a vibrant tech community. Additionally, for hiring top tech talent or exploring premium tech solutions, consider visiting &lt;a href="https://hng.tech/hire"&gt;HNG Hire&lt;/a&gt; and &lt;a href="https://hng.tech/premium"&gt;HNG Premium&lt;/a&gt;.&lt;/p&gt;

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