6

I created a new user:

$ sudo useradd -m Ari -p pass123

But when I went to login it said the password was incorrect, I know it's correct because I saved the command line log as a text file.

Other than that, at the same time I also created a group:

$ sudo groupadd testgroup1

and added the new account to it:

$ sudo usermod -a -G testgroup1 Ari

Why can't a log in?

  • 2
    On Ubuntu, as in Debian, you're supposed to use adduser and addgroup. That takes care of Stuff for you. – Faheem Mitha Mar 23 at 13:57
11

The -p option is looking for an encrypted password:

-p, --password PASSWORD

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

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.

You should use the following to change the password:

sudo passwd Ari

In order to use the -p option you must first encrypt the password. You can use some of the methods mentioned here such as:

$ mkpasswd
Password:
1puqSPGTnyi5o
$ sudo useradd -m Ari -p 1puqSPGTnyi5o

Note the mkpasswd utility is included in the whois package which can be obtained through apt

  • What would be the correct way to do it from the terminal? $ sudo useradd -m Ari pass123 or just creating the user then doing as you suggest? – Ari Victor Mar 23 at 13:54
  • 1
    The preferred and safe way is to set the password separately with passwd but I have updated the question to include instructions on encrypting a password for use with useradd -p – Jesse_b Mar 23 at 14:12
  • 3
    Don't use openssl passwd, and especially not with -crypt. It uses the obsolete DES-based crypt function, which among other things is limited to only 8-characters passwords (and 2-character salts). The openssl on my system does support the MD5-based hash ($1$), but not the newer SHA2-based hashes ($5$ and $6$), which are the ones commonly used on Linux-systems. – ilkkachu Mar 23 at 16:15
  • If you need to batch change passwords, use chpasswd. By default it runs the change through PAM, so you get a) the same hashing as with passwd, and b) the passwords updated to whatever it is your system actually uses (in case you have e.g. LDAP). It also does support e.g. -c SHA512, too, if you do need to bypass PAM. – ilkkachu Mar 23 at 16:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.