July 1, 2024, 12:51 p.m. | Kenneth Aigbuza

DEV Community dev.to

In this article, we'll walk through a bash script that reads user information from a text file, creates users and their groups, sets up home directories, generates random passwords, logs actions, and stores passwords securely.


Bash Script: create_users.sh



#!/bin/bash

# Define file paths
LOG_FILE="/var/log/user_management.log"
PASSWORD_FILE="/var/secure/user_passwords.txt"
INPUT_FILE=$1

# Ensure secure directory for passwords
mkdir -p /var/secure
chmod 700 /var/secure

# Function to generate random password
generate_password() {
tr -dc A-Za-z0-9 </dev/urandom | head -c 12
}

# Ensure log file exists …

actions article bash bash script directory file home information log logs management passwords random script stores text txt var

Information Assurance Engineer

@ Leidos | 6314 Remote/Teleworker US

SQL Database Admin - INT

@ General Dynamics Information Technology | USA AZ Fort Huachuca - 2133 Cushing St, Bldg 61801 (AZC012)

Network Engineer - Lead

@ QBE LLC | Arlington, VA, US

Cloud Managed Services Engineer

@ Versa Networks | Switzerland

Software Engineer - Microsoft Entra ID

@ BT Group | Snowhill, Birmingham, United Kingdom

Security Cloud Solution Architecture Manager

@ Microsoft | Issy Les Moulineaux, Hauts-de-Seine, France