Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
up vote 5 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

Your Answer


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.