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?
-
1What do you mean "add or modify the user"? Which user, and for what purpose? This does not sound like a normal request for a beginner in bash.John Zwinck– John Zwinck2011-07-03 17:21:29 +00:00Commented Jul 3, 2011 at 17:21
-
also this depends on your distro. But you can check man adduser or man useradd.hornetbzz– hornetbzz2011-07-03 20:51:05 +00:00Commented Jul 3, 2011 at 20:51
Add a comment
|
2 Answers
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.