Ankur
Ankur

Reputation: 1

Adding or Modifying User in Bash Shell Script

As I am trying to learn bash shell, I want to have some idea how can I add or modify the user in Bash Shell script?

Upvotes: 0

Views: 1030

Answers (2)

J-16 SDiZ
J-16 SDiZ

Reputation: 26910

Use adduser(8).

Upvotes: 0

Rakesh Sankar
Rakesh Sankar

Reputation: 9415

Quick Ex:

Adding an user:

createuser.sh

#!/bin/sh

user=$1 #first argument 
apache="www-data"
passuser=$2 # second argument
newpasswd=$(perl -e 'print crypt($ARGV[0], "S@LtStR!Ng")' $passuser)
createuser='/usr/sbin/useradd' # PATH to `useradd` package

##create and update password, then assign the apache group to the user
$createuser -d /home/$user -g $apache -m -s /bin/bash -p $newpasswd $user

Calling:

root@ip-ad-2as2-ds:#./createuser.sh test test1234

This way you can control the modify-user script, just change the createuser variable to have the proper modify-user (usermod) package.

Upvotes: 1

Related Questions