LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   usermod vs passwd - usermod not working (https://www.linuxquestions.org/questions/linux-newbie-8/usermod-vs-passwd-usermod-not-working-4175575656/)

scriptkiddy 03-23-2016 03:08 AM

usermod vs passwd - usermod not working
 
I have a CentOS machine, and I made a test user then set his password to splinter:

Code:

# useradd test1
# usermod -p splinter test1

Then I tested it by logging in:
Code:

mycentos login: test1
Password:
Login incorrect

The secure log said:
Code:

...
Mar 21 22:31:00 myhost unix_chkpwd[2685]: password check failed for user (test1)
...

So I tried to change password to splinter using passwd function:
Code:

# passwd test1
New Password: [typed splinter here]
Retype New Password: [typed splinter here]
#

Logged in just fine with user test1... So am I missing something? I chose splinter as the test password simply because it has no special chars etc, so I figured the usermod command would have no issues.

Why is usermod failing to change the password but the passwd command works just fine?

SK

cnamejj 03-23-2016 05:14 AM

Have a look through the man page for "usermod" and you'll find something like this.

Code:

      -p, --password PASSWORD
          The encrypted password, as returned by crypt(3).

That's from Ubuntu, so the wording may be different. But the idea still holds.

BW-userx 03-23-2016 10:25 AM

it worked for me in,
Void Linux
Code:

root@voided/home/userx >># useradd  deleteme
root@voided/home/userx >># usermod -p homeboy deleteme
root@voided/home/userx >># exit
exit
% 10:23 AM [userx@voided]~ >>$sudo -u deleteme
[deleteme@voided userx]$ whoami
deleteme
[deleteme@voided userx]$ exit
exit
% 10:24 AM [userx@voided]~ >>$whoami
userx

but logging in the other way, by logging out then back in under new user name password did not take.


found this it is way worth the read "A Complete Guide to Usage of ‘usermod’ command – 15 Practical Examples with Screenshots"

Code:

Create Un-encrypted Password for User

To create an un-encrypted password, we use option ‘-p‘ (password). For demonstration purpose, I’m setting a new password say ‘redhat’ on a user pinky.


A.Thyssen 03-23-2016 07:11 PM

Have a look at "/usr/sbin/chpasswd" which is a password changing program for batch (bulk) processing of users.

It can take the password in the clear, or a pre-encrypted passwd.

For example
Code:

  useradd  junkuser
  echo 'junkuser:junky password' | /usr/sbin/chpasswd


scriptkiddy 03-24-2016 01:43 AM

Interesting responses and information, thanks everyone, here are some thoughts.

@cnamejj I did see entry in the manpage about crypt, but I couldn't find any information on how to use it. For example, I couldn't find a yum package that had crypt in it, nor could I find a man page for crypt.

@BW-userx Its interesting that your login didn't work, but sudo did. I didn't try sudo, just logging in myself. Either way, the user wouldn't be able to log in if I did a usermod -p, so that's the issue I'm trying to fix. Was a good read

@A.Thyssen Well, it doesn't answer why usermod doesn't work, but that is a really interesting solution.

SK


All times are GMT -5. The time now is 12:26 AM.