Script for Adduser with Random pasword

I have just created a small bash script which will create user without asking for password. It will use random password. At the end it will show you username and password. I have made important 2 lines in bold and highlighted. Please note that It doesnt have any validation on User input or any other validation.

 

#!/bin/bash

echo -e "Enter Username you want to add:c"

read uname

echo -e "Enter Password age:c"

read page

PSD=`</dev/urandom tr -dc A-Za-z0-9 | head -c8`

useradd $uname

echo -e "$PSDn$PSDn"|passwd $uname

passwd -x $page $uname

echo -e "$uname is created. $PSD is its password and Passwd age is 14 days"

Neelesh Gurjar has written 122 articles

Leave a Reply