-   Linux - Software (
-   -   Problem with command useradd (

rosect 12-20-2011 12:43 AM

Problem with command useradd
I tried to use the command "useradd" to create an account. The complete command is:

useradd -p "$1$0up/D4zT$79ysvovohtDSgTRy7kLUr0" -s ~root/wcp/cli aaa

where "aaa" is the user name.

However, when I look at the /etc/shadow file, I see this:


The encrypted password is not what I gave in the command.

Can someone let me know why this happens? My OS is ""

(For certain reason, I do not want separate the command into "useradd" and "passwd". )

Thank you.

corp769 12-20-2011 09:10 AM

When you use the useradd command, supplying the password for it is in original text; It will be encrypted and added to /etc/shadow. You need to supply the actual password the user will be using, and not the encrypted hash.



rosect 12-20-2011 11:26 AM

Hi, Josh, Thank you for your reply.

With option "-p" in command useradd, you need to pass in encrypted password. If you use command passwd, then you may use plain text. Linux man page of useradd clearly says so.

I did try with plaintext as password with the command. In the /etc/shadow, the plaintext password is used as-is, not encrypted.

impert 12-20-2011 11:41 AM

Try using single quotes rather than the double ones. I think what's happening is that the shell is trying to interpret $0 $1, and $7. It didn't find $1 and $7, and so leaves them out. It did find $0, the value of which is "bash".
Or you could try something without $ and /.

rosect 12-20-2011 11:52 AM

Hi, impert,

Your suggestion worked. Thank you. And let me summarize how we should do.

1. If you pass in encrypted password without quotation marks, as impert pointed out, the '$' is not interpreted correctly.

2. If you pass in with (double) quotation mark, it is the same as above.

3. impert is correct. Pass in the encrypted password with SINGLE quotation mark. And that works!

Thank you, impert!

impert 12-21-2011 06:13 AM

You're welcome.
Actually, I learned something too. I've been using useradd for years without ever realising that there was the option to set the password with it.

corp769 12-21-2011 10:27 AM

Oops, I was thinking of something else. Sorry about that!

All times are GMT -5. The time now is 07:56 AM.