-   Linux - Newbie (
-   -   Adding Users with the "-p" option (

caps_phisto 01-08-2005 03:13 PM

Adding Users with the "-p" option
I was wondering if there were a special way of adding users with the -p option (passwd option).

I am writing a script that needs to add 100 users at the end of a kickstart installation and cannot input the password for each directly.

I have tried useradd -p <clear text passwd here> <user acct here>.

But when I try to login the password is incorrect. I am sure that I have missed something in the man page for useradd. And I know it probably has something to do with "crypt". But I cannot figure out what.

Thanks for all the help.

btmiller 01-08-2005 03:29 PM

Yes, you must specified the encrypted password, not the plaintext password. Here's a handy Perl script to generate the useradd command for a list of usernames and passwords (one entry per line, usernames and password separated by a space). WARNING: this is not tested.



while(chomp($line = <STDIN>)) {
  ($unme,$passwd) = split(' ', $line);

  # create a random salt, from perldoc -f crypt
  $salt = join '', ('.', '/', 0..9, 'A'..'Z', 'a'..'z')[rand 64, rand 64];
  $encp = crypt($passwd,$salt);
  print "useradd -p $encp $unme\n";

An alternative on a bunch of similar boxes is to create all the accounts on one machine and copy the password and shadow files over, or use NIS or LDAP for distributed authentication.

druuna 01-08-2005 03:30 PM


The -p option needs an already encrypted password. Take a look here:

There are probably more threads concerning this issue floating around.

Hope this helps.

caps_phisto 01-08-2005 07:25 PM

Thanks for the replies. I read all the links, and nothing from them worked out. I did not try the perl script above simply because I am not sure how that will work out with the rest of the script. (The rest of the script is BASH commands only, and as I stated before this is going to be a post-install script for a Kickstart install. I don't think I can change interpreters during the process...could be wrong though, I am new to KS Installs as well.). However, those articles and that perl script above did get my head moving again. This is what I came up with.

1. On the local NFS server (the one where my script is held anyways). I created a local user account with the password I wanted for the above mentioned 100 users. (no worries about security here, the Install server only gets hooked to the network when it is needed. It also only gets hooked up to rooms that it need to via a VLAN. Otherwise it is locked in the server closet, powered down and disconnected).

2. Then a simple:

/usr/sbin/useradd -p `cat /etc/shadow | grep <my server username here> | cut -d: -f2` <workstation account name here>
Again thanks for all the help. This really got my brain going again.

Berhanie 01-08-2005 09:10 PM

You might find this thread helpful.

caps_phisto 01-08-2005 10:21 PM

Yeah, I read that thread. The encrypt that came out of openssl was off by 3 characters thus the passwords did not match up. I didn't do too much investigating after that though.

Thanks for the additional help.

All times are GMT -5. The time now is 05:34 AM.