1833875 Members
3234 Online
110063 Solutions
New Discussion

Re: useradd script

 
SOLVED
Go to solution
Nick D'Angelo
Super Advisor

useradd script

Hello,

I would like to know if someone out there has improved the useradd script to do the following:

1) Look at the last entry in /etc/passwd and increment the UID by 1.
2) create the account (obviously)
3) assign it's initial password
4) Create their home directory.
5) Assign their group (default)
6) Did I miss something?

Suggestions/help appreciated.

Thanks,

Nickd

You gotta love these forums!!
Always learning
8 REPLIES 8
Paula J Frazer-Campbell
Honored Contributor

Re: useradd script

Hi Nick

Any outomatic script to add users has security implications especially asigning a password, it is by far safer to add your users yourself.

Using SAM will make the task slightly easier for you.

I am sure that many sysadmins will agree with me that doing it youself makes you aware of who is on your system and what that user is allowed to do.

HTH

Paula
If you can spell SysAdmin then you is one - anon
Nick D'Angelo
Super Advisor

Re: useradd script

Paula,

Thanks, I am fully aware of the security implications. I personally don't like to use Sam and would prefer to do it through vi. I was just looking for some automation, ok leaving out the password setting.

Thanks,
Nickd
Always learning
Madhu Sudhan_1
Respected Contributor
Solution

Re: useradd script

The script attached. This way everything else is default except userid. I doubt of assiging initial password thru useradd. If your system is trusted, the initial password is randomly generated and echoed onto stdout.

Regarding the password is concerned, you can edit (ofcourse thru script) and put an encrypted version of the password which you already know. But this is not recomended.


PS: The script doesn't include this part of useradd

Thanks,
Madhu


Think Positive
Paula J Frazer-Campbell
Honored Contributor

Re: useradd script

Hi Nick

This small script can be modified to make life easier - on option 1 I presumed that you would wish to look at the group file first to get the new users group.

-------------cut here----------------
continue="yes"
while [ "$continue" = "yes" ]
do
clear

echo "--------------------------------- "
echo " MENU "
echo " ----------------------- "
echo "| |"
echo "| 1 : Which group |"
echo "| 2 : 2nd bit |"
echo "| 3 : 3rd bit |"
echo "| 4 : 4TH bit |"
echo "| x : EXIT |"
echo " ---------------------- "
echo "| |"
echo " ---------------------- "
read ans
case $ans in
1) cat /etc/group|more
;;
2) 2nd bit
;;
3) 3 rd bit
;;
4) passwd

x) continue="no"
;;
X) continue="no"
;;
esac
done

---------------cut here-------------

HTH

Paula
If you can spell SysAdmin then you is one - anon
Nick D'Angelo
Super Advisor

Re: useradd script

Madhu,

Your script works fairly well, but it would be perfect if it would prompt me for the new userid first rather than include it in the script.

Nickd
Always learning
Suhas_2
Regular Advisor

Re: useradd script

Nick,
I have a small script to add many users ata time. This wrked fine during a major cut-over.
Hope this proves useful ....

Suhas.
Never say "Die"
Merlin the happy pig
Occasional Contributor

Re: useradd script

Just pass the userid and the group into the following script (Where /etc/skel/group is any default stuff you want in the home directory specified by the -d option to adduser -

USER=$1
GROUP=$2
useradd -g $GROUP -d /users/$USER -s /usr/bin/ksh -m -k /etc/skel/$GROUP $USER echo "\n\n$USER created and added to $GROUP\n
AUTHNUM=`/usr/lbin/modprpw -x $USER|awk -F= '{print $2}'`
echo "\nAuthorization number for $USER is $AUTHNUM"
echo "Press return"
read ans
return
A Headless Chicken does not stop for a Haircut
Madhu Sudhan_1
Respected Contributor

Re: useradd script

Try this. Requested changes are made.

Enjoy !
...Madhu
Think Positive