Avatar of mac_g
mac_g
Flag for Saudi Arabia asked on

Linux : adding the new user with password option,

i have created user with password option

#useradd -p user01 user01

When I tried to login with user01, am getting below error message, despite having correct password.

--
[user01@SRV1 ~]$ su - user01
Password:
su: incorrect password
--

I want to  give password option in Single command.

please advice how to achieve the same
LinuxLinux DistributionsLinux OS DevUnix OS

Avatar of undefined
Last Comment
Kevin Pham

8/22/2022 - Mon
Sudeep Sharma

In your question it seems that you are already logged in with user "user01"

[user01@SRV1 ~]$ su - user01

Log off and try to su - user01 again and check.

Sudeep
David Sankovsky

As far as I know there isn't a way to do so. Also it's very insecure!!!!
The password should be typed, to make sure that only the person who should have the required access. gets it.
Also, Don't open a new ticket on every question you have... I've 3 questions that you've opened today that relate to the same thing.
Please choose a solution for the question you left open and close them.
mac_g

ASKER
thanks David.As it is urgent no option but to raise the new question.
Your help has saved me hundreds of hours of internet surfing.
fblack61
David Sankovsky

People who answered you previous questions are notified when you post something new..
mac_g

ASKER
this activity has to perform on lot of users.
I want to simply the process by using single command.

@david, I agree it is insure

@sudeep, the output captured to show the error message while login, despite I give -p option in "useradd" command.
David Sankovsky

OHH you want to create a user and pass the password as a parameter?
try
useradd -p<password> username

Open in new window

There should be no space between the -p flag and the password
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
mac_g

ASKER
#useradd -p test02 test02

su - test02
Password:
su: incorrect password

==
when I am giving -p option as command line it is not working.
I tried multiple time ....

any way to fix this ?
Sudeep Sharma

there should be no gap between -p and your password.

The command should be:
useradd -ptest02 test02
mac_g

ASKER
==
[root@SRV ~]# useradd -paa aa
[root@SRV ~]# su - aa
[aa@SRV ~]$ su - aa
Password:
su: incorrect password
==
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
ASKER CERTIFIED SOLUTION
serialband

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Kevin Pham

Correct Syntax: useradd -p encrypted_password username

You cannot specify a plaint-text password and expect it to work. The password as you specify (if you view /etc/shadow) will be recorded exactly as it was typed.

You can do something like this as one line
useradd -p $(openssl passwd -1 <password>) <username>