4

Inside one of my scripts, I created an user based on a directory arrangement on another machine.

The thing is that this user, created without a password, behaves just as he had one : he has sudo rights but I simply can't sudo because it asks for a password that doesn't exist. I know I could simply passwd him as root, but the devised system has to work without intervention from local root privileged users.

I also cannot passwd as the user in question since passwd asks me for the same inexistant password.

I suppose that it is intended behavior, but then what is the eventual default password and what can I do to circumvent this ?

EDIT : Here is what the script does :

1: it rsyncs the home directories of the users who should be created or updated in /opt/sshgw/home (sshgw means ssh gateway) from our ssh gateway machine

2: it removes all authorized keys for every user of the machine running the script

3: it removes every user from the wheel group and performs usermod -L (I am not the author of the script and I do not really know why he locks the account, but whatever.) Though keep in mind that at this point only existing users are modified.

4: It creates users if they have been retrieved from the sshgw and they are not present on the local machine, then, if specified, they are added the wheel group. It then adds their public keys to their proper home directories and finally performs usermod -U.

The user's entry in /etc/passwd is normal.

Upon calling passwd, the users gets asked his current password (which can not exist for a user who has just been created without a password, mind you) in this fashion :

[splatpope@monitor sshgw]$ passwd
Changing password for user splatpope.
Changing password for splatpope.
(current) UNIX password:

I guess the culprit is usermod -U.

2
  • 1
    how is the user created exactly?
    – Braiam
    May 1, 2014 at 23:44
  • 1
    Yes, please provide some specifics as to how all this came to be and perhaps show this user's entry in the /etc/passwd /etc/shadow files.
    – slm
    May 1, 2014 at 23:50

2 Answers 2

7

A user is created by default as a locked account. The field that should contain the password hash in /etc/shadow will contain !!. When an account is locked, that account is available to root only (root can su but logins aren't allowed). If you 'unlock' the account which simply removes the !! you will be allowed to change the password.

[root@test ~]# su - test
[test@test ~]$ passwd
Changing password for user test.
Changing password for test.
(current) UNIX password:
[test@test ~]$ exit
logout
[root@test ~]# passwd -u test
Unlocking password for user test.
passwd: Warning: unlocked password would be empty.
passwd: Unsafe operation (use -f to force)
[root@test ~]# passwd -u test -f
Unlocking password for user test.
passwd: Success
[root@test ~]# su - test
[test@test ~]$ passwd
Changing password for user test.
New password:
2
  • I forgot to mention that I actually use usermod -U to unlock the password. The password seems to be unlocked, but it still asks for an hypothetic password when I try to actually set it up. May 6, 2014 at 23:15
  • Aaaaand, passwd -fu works. I guess the guy who wrote the script is bad. May 7, 2014 at 23:15
1

yoonix's answer already covered the fact that there is no default password.

To give the newly created user a password as the account is being created, you can do this:

useradd ... -p $(mkpasswd $Password) ... user_name

This assumes:

  • The password you want to give to this user is in the $Password variable.
  • You have the mkpasswd utility for encrypting passwords (this is in the whois package on my Debian box).

Default behavior is a disabled account, though. Quoting from useradd(8):

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

1
  • Well, I do not want to give them a password. May 7, 2014 at 23:16

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .