0

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?

2
  • 1
    What 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. Commented Jul 3, 2011 at 17:21
  • also this depends on your distro. But you can check man adduser or man useradd. Commented Jul 3, 2011 at 20:51

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

Comments

0

Use adduser(8).

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.