I created a user with password using the useradd
command.
Ok, I will take your word for that ... i.e. you attempted to create a new user with a password using only useradd
... Trying to imagine how you attempted that ... Probably using the -p, --password
option and provided PASSWORD as plain text like so:
$ sudo useradd -p PASSWORD harry
Well, that is not going to work as the password provided should be an encrypted password as stated in man useradd
:
-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.
Therefore, the password you type(which will be hashed/encrypted before comparing to the stored user's password "hash") is not actually the password stored on/expected by the system and the error su: Authentication failure
is actually what it it means as the password cannot be authenticated/matched this way ... su - harry
should work fine if you change the password using sudo passwd harry
then try su - harry
afterwords.
Furthermore, as also stated in the man useradd
excerpt above, this is not the recommended way of setting a password for the user.
The recommended way is to use passwd
after creating the user to set a password like so:
sudo passwd harry
This is the method used by adduser
... Which is a front-end user friendly Perl script to useradd
that you can inspect with:
cat /usr/sbin/adduser
to find out that it does that by calling the passwd
system executable in this code excerpt:
.
.
.
if ($ask_passwd) {
for (;;) {
my $passwd = &which('passwd');
# do _not_ use systemcall() here, since systemcall() dies on
# non-zero exit code and we need to do special handling here!
system($passwd, $new_name);
my $ok = $?>>8;
if ($ok != 0) {
.
.
.
Aftermath:
After using useradd
(without using and providing valid/proper arguments to the -d
, -m
and -s
options) to create your new user i.e. NOT like so:
sudo useradd -s /bin/bash -d /home/harry -m harry
Then, you probably most likely will end up with no home directory for the new user and with dash
(The default for /bin/sh
as defined in useradd -D
) and not bash
as your new user's default login shell ... Therefore, you might want to:
Create a home directory for the new user the right way like so:
sudo mkhomedir_helper harry
Change the login shell for the new user to bash
like so:
sudo chsh -s /bin/bash harry
Next time you create a new user, use adduser
instead as it is a user friendly command and will take care of all the above.