Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I have some application that needs to create users that have the same password as others. Is there a way to do this without having to edit the /etc/shadow manually? Some sort of command?

share|improve this question
add comment

1 Answer 1

up vote 4 down vote accepted

On Linux, you can do this with the useradd or usermod commands from the shadow utilities suite, because they accept a password hash as an option. You'll need to extract the other user's password hash from /etc/shadow manually.

h=$(</etc/shadow awk -vuser="old_user_name" -F: '$1==user {print $2}')
useradd -p "$h" new_user_name

Note that if anyone obtains the shadow file, they'll know immediately that the two users have the same password, because the two hashes will be using the same salt. There's no way to fix that without having to enter the actual password (which cannot be recovered from /etc/shadow short of using brute force).

Note that on most Linux installations, the command line of a running process is visible to all users. So if there are other users on the machine, they might be able to see the password hash (which gives them something they can try to brute-force offline). This can be fixed by using frameworks such as SELinux that hide process command lines from other users.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.