|
-
June 22nd, 2004, 02:14 AM
#1
unix useradd script help please.
ok, my situation is we have a HPUX server and for certain apps each user has to have a certain profile. well i wanna create a useradd script that prompts for the username and password, and it sets the UID to the next available UID and creates the default home directory and everything. Well i have everything fine except the password part. I've looked over the man pages for useradd and i dont see a switch to set the password. so far from what i have is it would create the user for me but after im done runnin the script i would have to set the password for the user manually, i want the script to give the user the password i specify for the script. Heres an example of what im thinking but its not working...
#!/bin/sh
echo Enter Username
read username
echo Enter Password
read password
grep /etc/passd $username
if [ $? -ne 1 ]
then
echo 'Username already in use...'
else
echo "Adding user..."
useradd $username
echo "Making user Home Directory..."
mkdir /home/$username
echo "Creating user Password..."
passwd $password
fi
i get the error that the login ID is invalid or somethin like that (im at home now) and im guessing because it thinks when it executes the passwd command its trying to change the passwd for root or whatever user is running the script. Can anyone help me please. Im lookin for a way to specify what the password should be set with with $password. Someone please. help. Thanks.
keep in mind this is a unix, im gettin mixed results obviously on my linux machine. it works when i take out the grep on my linux machine but ends in error, and it asks me to renter the password at the end of the script, but it works nevertheless. i want it to exit cleanly and not ask me again at the end of the script for the password. i dont have access to a unix machine right now only to my linux one. help is much appreciated. thanks.
-
June 22nd, 2004, 02:35 AM
#2
You'll need to use expect in order to script this part.
Info can be found here -> http://expect.nist.gov/
If memory serves, it comes with sample scripts that should point you in the right direction.
-
June 22nd, 2004, 02:46 AM
#3
Well, I recommend this:
# useradd -c "Name Of Person" -m username
If you're on HPUX 11, and maybe with 10.20, it will have created the user with the next available UID and added them into a default group as well as having locked their account until you (as root) set it. This prevents root-shell scripts that are auto-executed through various nefarious methods from creating UID 0 accounts (as well as other issues).
Then you do the following:
There's really no way around this and honestly, you don't want that. Creating a custom script for that would be more headache than you can imagine (trust me, been there, finding next available low-count UIDs sucks) so this is the best method. 'useradd' tells you if the person exists, does all the adding and manipulation for you, mucks with the /etc/passwd and updates the backup, etc. Easier, by far.
EDIT: what jonathan said works too, but it's a bit more complicated, hehe...
We the willing, led by the unknowing, have been doing the impossible for the ungrateful. We have done so much with so little for so long that we are now qualified to do just about anything with almost nothing.
-
June 22nd, 2004, 02:55 AM
#4
so theres no real way in doin it within the script to prompt for the password and have it set to what you specify? yes i am on hpux 11.11. thanks for advice guys.
-
June 22nd, 2004, 04:07 AM
#5
There is a tool that does exactly what you are trying to do located at www.cyberspace.org , the script listens for connections, prompts for login credentials, then walk the user through registration if they don't have a username and password.
--PuRe
http://www.pureehosting.com
Hosting PHP Information Technology Webmaster Resource Computer Security
-
June 22nd, 2004, 07:01 AM
#6
try this
#!/bin/sh
echo Enter user login
read loginID
echo Enter user name
read username
gid_def=group
share_root=/u/shared
grep $loginID /etc/passwd
if [ $? -ne 1 ]
then
echo 'already in system '
else
echo "Adding user..."
useradd -G$gid_def -c"$username" -d /usr/$loginID $loginID
echo "Making user directory..."
mkdir /usr/$loginID
chown $loginID:$gid_def $loginID
echo "Set unix users password..."
passwd $loginID
echo "Set Facetwin password..."
fct_encrypt -b
fct_encrypt $loginID
mkdir /u/share/$loginID
chmod 700 $share_root/$loginID
fi
-
June 22nd, 2004, 08:57 AM
#7
If you have not already got enough here is the freebsd adduser script. It does exactly what you are looking to do
Do unto others as you would have them do unto you.
The international ban against torturing prisoners of war does not necessarily apply to suspects detained in America\'s war on terror, Attorney General John Ashcroft told a Senate oversight committee
-- true colors revealed, a brown shirt and jackboots
-
June 22nd, 2004, 06:43 PM
#8
reaper thanks, i've found that script but i havent wanted to include all that. i think i have found somethin that has worked, heres what we have so far:
#!/bin/sh
echo Enter Username
read username
grep $username /etc/passwd
if [ $? -ne 1 ]
then
echo "Username Already in use..."
else
echo "Adding User..."
useradd -g optim $username
passwd $username
echo "Making Home Directory..."
mkdir /home/$username
chown $username ptim /home/$username
chmod 755 /home/$username
fi
that works but now im makin it so it makes 'em change the password next time they login with the -f switch after passwd but its not workin that way, thanks for all the help guys, thanks alot. im still takin suggestions i try 'em all out. i wanna do it more with a script rather than a utility too. thanks guys.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
|