1

How do I create a crypt(3) encrypted password in a Windows DevBox that a remote CentOS 7 server can interpret successfully when creating a new user account via the following useradd command in a bash script?

useradd -u 12345 -g users -d /home/username -s /bin/bash -p '$1$NNfXfoym$Eos.OG6sFMGE8U6ImwBqT1' username

For testing purposes, let's assume that the cleartext version of the password should be Whirlpool_Sauna_Soap

When I man useradd, I get the following for -p

   -p, --password PASSWORD
       The encrypted password, as returned by crypt(3). The default is to
       disable the password.

       Note: This option is not recommended because the password (or
       encrypted password) will be visible by users listing the processes.

       You should make sure the password respects the system's password
       policy.

I am using putty to log in to the remote CentOS 7 server from a Windows DevBox. I would like to scp the file that contains the script from the Windows DevBox to the remote CentOS 7 server, and then run the script via SSH connection.

1
  • You need to run a program that can call a compatible crypt library routine. You could write such a thing inC, but python has docs.python.org/2/library/crypt.html and perl also does. So the question you need to answer is what tools you have on your Windows DevBox? Would you accept a solution that uses ssh to run a command on your CentOS box, and if so what do you have available on that box? Could you use useradd roo create the account without setting the password and then use chpasswd to set it? Commented Nov 23, 2016 at 7:49

1 Answer 1

1

I also used a script to generate users like this:

useradd -u 12345 -g users -d /home/username -s /bin/bash -p '$(openssl passwd -1 Whirlpool_Sauna_Soap)' username

3
  • Probably better to leave off the -1 as the OP was asking for crypt(3) compatible, although I agree that these probably should not be used. Commented Nov 23, 2016 at 22:51
  • Thank you and +1 for taking the time to answer. I guess I feel a little unsatisfied putting the password in clear text like that. ... I also have not tested this to see if it is crypt(3) compatible. Commented Nov 28, 2016 at 6:10
  • Well... You don't need to. You can just create the password with this command and then put the hash in the script... Commented Nov 28, 2016 at 6:19

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.