- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Adding 3000 user and setting there password via a ...
Categories
Company
Local Language
Forums
Discussions
Knowledge Base
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-22-2001 05:46 AM
06-22-2001 05:46 AM
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-22-2001 05:58 AM
06-22-2001 05:58 AM
Re: Adding 3000 user and setting there password via a script.
you may want to use "/usr/sbin/useradd" if you type the command without any option you'll receive a list of options.
If you have a list of users, e.g. form a file you can read in the lines of the file in a while loop. I'll have to lookup the correct syntax....
rainer
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-22-2001 06:21 AM
06-22-2001 06:21 AM
Re: Adding 3000 user and setting there password via a script.
so if you have a file with a list of users, e.g.
user1
user2
user3
and it is named users.txt you can start off with you script like:
#!/usr/bin/ksh
# this will setup users from users.txt
N=100
cat users.txt |while read i
do
N=`expr $N + 1`
useradd -u $N -g 20 -s /sbin/false -c generic $i
done
This will create passwd entries for all users from users.txt. They will belong to group 20 (users) and have "no shell" and they will have as description "generic"
hope this helps.
rainer
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-22-2001 06:25 AM
06-22-2001 06:25 AM
Re: Adding 3000 user and setting there password via a script.
Save your passwd and group files, just in case
cp -p /etc/passwd /etc/passwd.good
cp -p /etc/group /etc/group.good
Add a dummy user, and assign a passwd. Grab this passwd (make sure it has no metacharacters in it, such as "/$+" etc.) Let's assume it's abcdefgh
Create a file, say, "/tmp/file", one line per user
cat /tmp/file | while read user ; do
useradd $user (+ any other options you like)
sed "s/$user:\*:/$user:abcdefgh:/" > /tmp/passwd
mv /tmp/passwd /etc/passwd
passwd -f $user
done
chmod 444 /etc/passwd
Check all is OK before logging out. Any problems, move the saved files back into place
Note - passwd -f forces them to change their password next time they login, by putting ",.." after the password.
Robin.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-22-2001 06:43 AM
06-22-2001 06:43 AM
Re: Adding 3000 user and setting there password via a script.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-22-2001 06:50 AM
06-22-2001 06:50 AM
Re: Adding 3000 user and setting there password via a script.
The /etc/passwd password field is one way translation.
If you add an entry to the password field, you are adding a decripted string, not the password... thank God for that!
So, I believe the only way is to get the users to set their passwd on first login.
Unless you set 3000 of them yourself.
Man passwd just to see if you can do it, but I really doubt it.
Bill
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-22-2001 06:58 AM
06-22-2001 06:58 AM
Re: Adding 3000 user and setting there password via a script.
am I understanding it right that you just move the new gernerated file over /etc/passwd?
Did you keep in mind to keep the existing users especially root !
I'd suggest to change the "mv" line to a line like
cat /tmp/passwd >> /etc/passwd
regards,
rainer
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-22-2001 07:09 AM
06-22-2001 07:09 AM
Re: Adding 3000 user and setting there password via a script.
troy - are your passwords already encrypted. If they're not, I'm not sure you can do it through a standard script.
Robin.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-22-2001 07:14 AM
06-22-2001 07:14 AM
SolutionHi,
If you have old passwd file insert lines in
new one. If not, I think I know how to do,
see below...
You can create users like others said and you
will obtain a /etc/passwd like that :
....
user2000:...:.......:...
....
After you need to change all passwd, and you
have a file with user and passwd (not crypted)
like that :
user:passwd
So now you need to insert encrypted passwd :
Compile this small program in /tmp :
1) copy it in /tmp/cr.c
2) cc cr.c -o cr
/* DEBUT PRG */
#include
#include
void main (narg, args)
int narg;
char ** args;
{ printf ("%s",crypt (args[1],args[2]));}
/* FIN PRG */
Now you can use this prg like that :
/tmp/cr passwd key
key is a two letters string (which take place
at the beginning of encrypted passwd,
man 3 crypt for more informations)
now a script example (you made a file with
user:passwd) I use az like key:
cat >/tmp/passwd.users
for i in `cat /tmp/file`
do
USER=`echo $i | cut -f1 -d':'`
PWD=`echo $i | cut -f2 -d':'`
grep "$USER" /tmp/passwd | awk -F':' -vVAR=`/tmp/cr $PWD az` '{print $1:VAR:$2:$3:$4:$5:$6:$7}' >> /tmp/passwd.users
done
Now You need to replace lines in passwd by new
ones in /tmp/passwd.users
HTH
Herve
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-22-2001 07:24 AM
06-22-2001 07:24 AM
Re: Adding 3000 user and setting there password via a script.
The following perl one-liner can be used for each password, where $pwd is read from your password list, and "ue" is the encryption salt (randomizer). It doesn't have to be "ue", just any two characters would do.
perl -e 'print crypt("$ARGV[0]","$ARGV[1]") . "\n";' $pwd ue
If you want me to incorporate this into my earlier script, please let me know.
Robin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-22-2001 07:44 AM
06-22-2001 07:44 AM
Re: Adding 3000 user and setting there password via a script.
You learn something new every day here!
Later,
Bill
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-22-2001 07:50 AM
06-22-2001 07:50 AM
Re: Adding 3000 user and setting there password via a script.
No my password list is not encrypted.
Please incorporate the perl one-liner in your earlier script.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-22-2001 08:44 AM
06-22-2001 08:44 AM
Re: Adding 3000 user and setting there password via a script.
Think you can use :
(/tmp/file format is already the same, a list
of user:passwd:and others informations)
cat >/tmp/passwd.users
cp /etc/passwd /tmp/passwd.ORG
cp /etc/passwd /etc/passwd.ORG
for i in `cat /tmp/file`
do
USER=`echo $i | cut -f1 -d':'`
PWD=`echo $i | cut -f2 -d':'`
# You can do the same for others fields (for example home_dir...)
useradd _u $USER ... # add other parameters
EPWD=`perl -e 'print crypt("$ARGV[0]","$ARGV[1]") . "\n";' $pwd ue `
grep "$USER" /tmp/passwd | awk -F':' -vVAR=$EPWD '{print $1:VAR:$2:$3:$4:$5:$6:$7}' >> /tmp/passwd.users
done
cat /tmp/passwd.users >> /tmp/passwd.ORG
Now verify if /tmp/passwd.ORG is good
and copy it to /etc/passwd
HTH
Herve
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-22-2001 09:13 AM
06-22-2001 09:13 AM
Re: Adding 3000 user and setting there password via a script.
Error, in my script I made a copy of Robin's
Perl command but first parameter is $PWD
instead of $pwd
Sorry :-(
Herv?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-22-2001 10:39 AM
06-22-2001 10:39 AM
Re: Adding 3000 user and setting there password via a script.
#!/usr/bin/ksh
function getSalt {
typeset Salts
typeset -i num
set -A Salts a b c d e f g h i j k l m n o p q r s t u v w x y z A B C D E F G H I J K L M N O P Q R S T U V W X Y Z 0 1 2 3 4 5 6 7 8 9 . /
num=$(($RANDOM / 512 ))
salt1=${Salts[$num]}
num=$(($RANDOM / 512 ))
salt2=${Salts[$num]}
print "$salt1$salt2"
return
}
function encodePwd {
typeset pwd="$1" Salt="$2"
typeset -L8 Pwd
typeset -i num
num="${#pwd}"
if [[ $num -gt 7 ]] ;then
Pwd=$pwd
pwd=$Pwd
else
while (( $num < 8 ))
do
pwd="${pwd}\000"
(( num = $num + 1 ))
done
fi
print "${pwd}$Salt" | /usr/lbin/makekey
return
}
function editFile {
ex -s $pwdFile <<-EODATA
/${1}:
s!:.*:!:${2}:!
wq
EODATA
return
}
cat yourUserAndPasswordFile |
while read user newPwd
do
# get your salt
Salt=$(getSalt)
#encode you password
encodedPwd=$(encodePwd "$newPwd" "$Salt")
#edit your file
editFile "$user" "$encodedPwd" >/dev/null
done
now this does no validation of appropriate usernames or passwords. And doesn't support things like trusted systems, NIS, etc.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-24-2001 11:28 PM
06-24-2001 11:28 PM
Re: Adding 3000 user and setting there password via a script.
This assumes each line in /tmp/file is of the form:
username password
==============================
cat /tmp/file | while read user pwd ; do
useradd $user (+ any other options you like)
perl -e 'print crypt("$ARGV[0]","$ARGV[1]") . "\n";' $pwd ue | read p
sed "s/^$user:\*:/$user:$p:/" > /tmp/passwd
mv /tmp/passwd /etc/passwd
passwd -f $user
done
chmod 444 /etc/passwd
==============================
Hope this helps,
Robin.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-25-2001 12:21 AM
06-25-2001 12:21 AM
Re: Adding 3000 user and setting there password via a script.
It's your first question on this forum...
There is a custom on this forum :when someone
give you informations (sometimes a solution of
your problem), it's a good idea to give him
points...
Regards,
Herv?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-25-2001 03:45 AM
06-25-2001 03:45 AM
Re: Adding 3000 user and setting there password via a script.
You folks were sending some good stuff at me and needed sometime to apply the scritps. This call can be closed.
thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-25-2001 04:02 AM
06-25-2001 04:02 AM
Re: Adding 3000 user and setting there password via a script.
I think you success now... Well, could you
give the community your really tested and
apply script... For the next one who want to
do that...
Thanx
Herve