Operating System - Linux
1820072 Members
2447 Online
109608 Solutions
New Discussion юеВ

How to set MD5 encrypted password for new user

 
SOLVED
Go to solution
Vitaly Karasik_1
Honored Contributor

How to set MD5 encrypted password for new user

I'd like to create a user account on every new linux box. I'd like to setup password for this use using MD5 hash from /etc/shadow from existing system.
But as far as I see, "useradd -p" accepts only "crypt", not MD5.

Is there another simple method to set up password for new user using MD5 hash?

(there is RHEL3 update 6)
7 REPLIES 7
Alexander Chuzhoy
Honored Contributor

Re: How to set MD5 encrypted password for new user

I wonder if the following will help, assuming that in authconfig "use md5 passwords" is selected.
useradd user1;
echo password |passwd user1 --stdin;
Vitaly Karasik_1
Honored Contributor

Re: How to set MD5 encrypted password for new user

as far as I see, in your example I should using palin-text password and I'd like to avoid this.
I want to use MD5 string from existing shadow file like "$1$.fdYDaVj$G8zLaaP/Eym0hkokPCnSZ0"
g33k
Valued Contributor

Re: How to set MD5 encrypted password for new user

If your system use MD5 hashes (MD5crypt function) as standard(for all users)...
You can just add new user with any password and then just edit /etc/shadow (and it should) be OK, of course must be root to do that.
Vitaly Karasik_1
Honored Contributor

Re: How to set MD5 encrypted password for new user

g33k, thanks, I'm aware about possibility to edit /etc/shadow with sed/perl/..., but I'd like to do this in more elegant way.
Matti_Kurkela
Honored Contributor
Solution

Re: How to set MD5 encrypted password for new user

There is a command "chpasswd".
First you must create a file (or something you can pipe to chpasswd command) with the following structure:
:
:
...

The passwords can be encrypted or plaintext. If the passwords are already encrypted (by whatever method), you must use the -e option with the chpasswd command.
MK
Vitaly Karasik_1
Honored Contributor

Re: How to set MD5 encrypted password for new user

Matti, many thanks! it works.

happy sysadmin day to you and all forumers!
Vitaly Karasik_1
Honored Contributor

Re: How to set MD5 encrypted password for new user

thanks to all - chpasswd works!