• Home
  • About
  • Tech
  • Projects
  • Contact
TjWallas.DevOps().Labs>

How to automate creation and deletion of users on ubuntu

11/11/2010

 
Here is a code that does it:
#Author: Amr Tj. Wallas
#Subject: Bash script for creating accounts for the 9th semester students.
#THIS SCRIPT HAS TO BE RUN AS ROOT OR WITH SUDO PERMITIONS ON EACH HOST (I still dunno parallel ssh but it can be integrated easily)

#Adds user with login asr01 and password lol123 (Encrypted)
sudo useradd --create-home --password $(perl -e 'print crypt("lol123", "aa")') asr01

#And so on:
sudo useradd --create-home --password $(perl -e 'print crypt("lol123", "aa")') asr02
sudo useradd --create-home --password $(perl -e 'print crypt("lol123", "aa")') asr03
sudo useradd --create-home --password $(perl -e 'print crypt("lol123", "aa")') asr04
sudo useradd --create-home --password $(perl -e 'print crypt("lol123", "aa")') asr05
sudo useradd --create-home --password $(perl -e 'print crypt("lol123", "aa")') asr06

#HINT: to completely delete an account along with it's home directory and files use:
#  userdel --remove LOGIN_NAME_GOES_HERE

A few Notes:

. For the useradd command, --create-home specifies that we want to create a directory for that user in /home.

. For the userdel command --remove means that we want to delete the home directory of the user.

What's so awesome about this script?

The Great thing about this script is that you can run it remotely on multiple hosts (PCs) via parallel ssh because it's completely silent and doesn't require any input or bug you with annoying error messages that pause the execution of the code.

Another cool thing, is that u can further tweak it using perl combined with a little linux Bash syntax to read the user names and passwords Dynamically from a file =D

Download & Exec:

users-create.sh
File Size: 0 kb
File Type: sh
Download File


You can simply download it to your Desktop and run the script by typing the following command in your Terminal:
sudo bash Desktop/users-create.sh

Comments are closed.
Powered by Create your own unique website with customizable templates.