Bulk user add script
Hi Guys,
I'm running postfix mail server. It's using /etc/passwd auth. Everything is working charm and currently I'm in a need to add users in bulk around 2000. It's not possible to add all the users by typing commands. With the users list I have append the useradd command and made a simple script. All the users have added. But now the problem is to set password for those password. I can use the same formula I used to add the users. But in passwd -p option requires the encrypted password. If I can able to set any common password means it's also fine. But user name is different. Anybody know how to achieve this with script or any easy method? Thanks a lot in Advance... -- Hari. |
I belive you should be able to use that "passwd" alternative you mentioned. Just create a user X with a password "secret" or something. Copy the encrypted string for user X from /etc/shadow, and use that string as input to the "passwd" or "usermod" command.
|
You need to use something like crypt to create the encrypted password.
Example perl script: Code:
#!/usr/bin/perl Also you probably should change the salt, but keep in complex. |
Quote:
|
Quote:
new-user.sh Code:
#!/bin/bash Code:
user1,password1 It currently will echo what it will output to the system when you run it... to do the process for real remove the echo. Good luck. |
Also look at newusers to do any future job like this, & apg to generate passwords.
|
Quote:
|
Two alternates I know!!
1. Using Shell script
Code:
echo $PASS | passwd $USER --stdin Code:
#!/usr/bin/perl |
Quote:
|
As already suggested by ArchToad6 look at newusers.
Create a file containing the users to be created, in my example this is called userlist: Code:
user1:Passwd1::1000:Test User 1:/home/user1:/bin/bash Code:
newusers userlist passwords are limited to maximum 8 characters (everything after that is ignored) As userlist contains unencrypted passwords, you must take steps to protect this file (or delete it once it's been used). EDIT:- Incidently, I tried mkpasswd and it works for me: Code:
echo Password|mkpasswd -s Quote:
|
Alternative bash script:
Code:
#!/bin/bash |
Quote:
To me it seems like mkpasswd only creates a random password, not a encrypted password: Code:
[root@server ]# echo Password|mkpasswd An interesting observation is that I don't have an "-s" option available: Code:
[root@server ]# echo Password|mkpasswd -s |
Quote:
Try: Code:
mkpasswd Password Sm Quote:
EDIT:- removed my first question as I realise it did not originate from the OP |
Quote:
Anyway, I've come accross cases where I need to create an encrypted password for a user, and to accomplish this I've had to run the clear text password through "passwd <someuser>" to get the hashed password. I've had to use this approach on the few servers we've got that doesn't use LDAP. Quote:
|
Quote:
Quote:
Quote:
|
All times are GMT -5. The time now is 09:25 PM. |