0

I use CentOS5. I'm trying to read a username and a password in a bash script so I can create a new unix user.

useradd -p $password $login

the problem here is that the password is not encrypted later in /etc/shadow.

In useradd man pages it is meant to specify passwords encrypted with crypt which is not a bash command. How can i use this function from a Bash script? Or is there any command for encrypting strings?

Chedy2149
  • 2,821
  • 4
  • 33
  • 56
  • pls look at this - http://stackoverflow.com/questions/1020534/useradd-using-crypt-password-generation – Bill May 17 '13 at 10:28
  • 5
    this is from man page of `useradd` -- `-p : "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."` – Bill May 17 '13 at 10:29
  • +1 to Bill's comment. When it comes to security, don't take any shortcuts. Ever. – DevSolar May 17 '13 at 10:52

1 Answers1

0

You could use OpenSSL for this. Its passwd command uses crypt by default.

$ openssl passwd secret
xzQbh15rXTn1c
Cairnarvon
  • 25,981
  • 9
  • 51
  • 65