LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Give password simultaneously for multiple users (https://www.linuxquestions.org/questions/linux-newbie-8/give-password-simultaneously-for-multiple-users-622980/)

bittus 02-22-2008 02:54 AM

Give password simultaneously for multiple users
 
hi every1,

I would like to duplicate present users of a Linux box into another one. I created the users using a shell script. Now can anyone suggest an idea to give same password for all the users simultaneously. (Like all users have the same password and they will change it according to their wish later)

Thanks in advance

rayfordj 02-22-2008 08:43 AM

if you just want them to all have the same password you could run through a for loop.

something like:
Code:

for i in user1 user2 user3 user4; do echo password | passwd --stdin ${i}; done
or if you have a filename with one username per line:
Code:

for i in $(cat /tmp/users.file); do echo password | passwd --stdin ${i}; done
or more simply set one password and then manually copy the hash from /etc/passwd (or /etc/shadow, if using shadow) and paste it for the remaining;
this isnt very secure (if anyone can read the shadow file they can clearly see that the hashes are the same so identifying the password for one users opens it up for all users) but then again, neither is setting the same password for multiple users. however, it does very from situation to situation as to what you do and why you decide to do it.

Code:

user1:$1$O07m28jy$ifVhJIq5NvrQar/ghQ7cg0:13901:0:99999:7:::
user2:$1$O07m28jy$ifVhJIq5NvrQar/ghQ7cg0:13901:0:99999:7:::
user3:$1$O07m28jy$ifVhJIq5NvrQar/ghQ7cg0:13901:0:99999:7:::


you may even be able to modify your shell script used to create the users to modify the password as well depending on its structure and design.

I'm sure there are any number of other possible ways to accomplish this same task; some more easily and some more robust/complex;

bittus 02-24-2008 06:46 PM

Thanks a lot buddy. I would try any of these and let u know abt the success. . . . .

bittus 02-25-2008 12:29 AM

Now i hav another quewry.

I hav a file with usernames and another with corresponding userids. I tried a script to create user by accepting username from one file and corresponding id from the other, but the loop executes infinitely. Can any1 help me to create username from both.

Thanks

chrism01 02-25-2008 12:52 AM

Show use the code... also, don't you mean create 'user' not 'username' ?


All times are GMT -5. The time now is 12:06 PM.