Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Linux : adding the new user with password option,

Posted on 2016-07-25
11
Medium Priority
?
167 Views
Last Modified: 2016-07-26
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
0
Comment
Question by:mac_g
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 2
  • +2
11 Comments
 
LVL 30

Expert Comment

by:Sudeep Sharma
ID: 41727887
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
0
 
LVL 7

Expert Comment

by:David Sankovsky
ID: 41727889
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.
0
 

Author Comment

by:mac_g
ID: 41727892
thanks David.As it is urgent no option but to raise the new question.
0
Amazon Web Services EC2 Cheat Sheet

AWS EC2 is a core part of AWS’s cloud platform, allowing users to spin up virtual machines for a variety of tasks; however, EC2’s offerings can be overwhelming. Learn the basics with our new AWS cheat sheet – this time on EC2!

 
LVL 7

Expert Comment

by:David Sankovsky
ID: 41727898
People who answered you previous questions are notified when you post something new..
0
 

Author Comment

by:mac_g
ID: 41727901
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.
0
 
LVL 7

Expert Comment

by:David Sankovsky
ID: 41727905
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
0
 

Author Comment

by:mac_g
ID: 41727920
#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 ?
0
 
LVL 30

Expert Comment

by:Sudeep Sharma
ID: 41727985
there should be no gap between -p and your password.

The command should be:
useradd -ptest02 test02
0
 

Author Comment

by:mac_g
ID: 41728002
==
[root@SRV ~]# useradd -paa aa
[root@SRV ~]# su - aa
[aa@SRV ~]$ su - aa
Password:
su: incorrect password
==
0
 
LVL 30

Accepted Solution

by:
serialband earned 2000 total points
ID: 41728595
You can't add a plain text password that way.  You're supposed to use the encrypted password hash. (what you would find in /etc/shadow).

useradd -p<user1_encrypted_hash> user01


You can use openssl to generate the password with a salt.
openssl passwd -1 -salt abc user01
$1$abc$ajQu7bKl0KZgRhWbXLR6g1

You use the salted hash as your password.
useradd -p$1$abc$ajQu7bKl0KZgRhWbXLR6g1  user01

You could technically combine then.  (Please note:  Use the backquote found under the tilde (~) symbol near the top left on a US keyboard layout.)
useradd -p`openssl passwd -1 -salt abc user01`  user01

This should only ever be done on a secure system that isn't accessible to all users, as they can watch the process table and grab every one of your passwords.  You should clear your history file (history -c in bash).  You should also force users to change their password and make this a one time, initial password only.

Generally, you should create the passwords separately.
0
 
LVL 3

Expert Comment

by:Kevin Pham
ID: 41730141
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>
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will explain how to establish a SSH connection to Ubuntu through the firewall and using a different port other then 22. I have set up a Ubuntu virtual machine in Virtualbox and I am running a Windows 7 workstation. From the Ubuntu vi…
Join Greg Farro and Ethan Banks from Packet Pushers (http://packetpushers.net/podcast/podcasts/pq-show-93-smart-network-monitoring-paessler-sponsored/) and Greg Ross from Paessler (https://www.paessler.com/prtg) for a discussion about smart network …
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
Suggested Courses

670 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question