Saturday, April 20, 2024
 Popular · Latest · Hot · Upcoming
4
rated 0 times [  4] [ 0]  / answers: 2 / hits: 868  / 2 Years ago, sun, january 23, 2022, 4:32:00

I am currently using ubuntu 20.04 machine.
I created a user with password using the useradd command.
I need to change the PATH variable of that user. So i used su - <username> to interactivelly login to the user's shell. When it asked for the password, I provided the password of the user. But I am getting the below error.


ubuntu@ip-172-31-49-109:~$ su - harry
Password:
su: Authentication failure

Does anyone know how can I fix this and how I acn change the PATH variable of the user


More From » 20.04

 Answers
0

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:



  1. Create a home directory for the new user the right way like so:


    sudo mkhomedir_helper harry


  2. 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.


[#1] Monday, January 24, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
darpose

Total Points: 424
Total Questions: 99
Total Answers: 121

Location: Jersey
Member since Fri, Oct 1, 2021
3 Years ago
darpose questions
Tue, Apr 25, 23, 23:44, 1 Year ago
Wed, Dec 15, 21, 14:42, 2 Years ago
Wed, Jun 2, 21, 23:41, 3 Years ago
;