6

I have created user using below command

useradd myuser

Then, I tried to do change password with following command

usermod --password mypwd myuser

(I know plain password is not a good way, but for time being I am doing this)

I have tried to login myuser with mypwd. But, it's not allowing to login (incorrect password).

I could use passwd myuser (working fine). There are some constraints, so I am doing with usermod.

Is anything I am missing in usermod ? or Is there any alternatives to do change password other than passwd username?

Jeff Schaller
  • 66,199
  • 35
  • 114
  • 250
Spike
  • 989
  • 1
  • 12
  • 19
  • 1
    See [How can I assign an initial/default password to a user in Linux?](http://unix.stackexchange.com/questions/57796/how-can-i-assign-an-initial-default-password-to-a-user-in-linux) – steeldriver Aug 31 '16 at 08:22

1 Answers1

14

The parameter given to usermod --password is expected to be the encrypted password, as returned by the crypt() function. If you look in /etc/shadow (assuming you're using local password storage) you'll see the string you specified stored as-is in myuser's entry...

If you really want to use usermod for this, you can generate the appropriate value using openssl passwd:

usermod --password $(openssl passwd mypwd) myuser

or better still

usermod --password $(openssl passwd -1 mypwd) myuser
Stephen Kitt
  • 411,918
  • 54
  • 1,065
  • 1,164
  • Just to reinforce that one should use `-1`, otherwise `openssl` will default to `-crypt` and truncate the password at 8 chars with a "Warning: truncating password to 8 characters" message. – That Brazilian Guy Oct 08 '20 at 18:19