Operating System - Linux
1827969 Members
3362 Online
109973 Solutions
New Discussion

Re: creating a user account from the command line

 
SOLVED
Go to solution
linuxtolinux
Frequent Advisor

creating a user account from the command line

hello,
i am using red hat 8.0 and i am trying to create a new user account from the command line using (useradd -p password username ).I have a problem in the password field : when i checked my /etc/shadow list, the password for the user username doesn't appear encrypted and also when i tried to login using this account i couldn't.Noting that i didn't encounter any problems if i use the gui or using ( useradd username and then passwd username from the command line).Is there somthing wrong in useradd -p password username or somthing else.....(the man useradd shows this format)

regards:
naji
4 REPLIES 4
Stuart Browne
Honored Contributor
Solution

Re: creating a user account from the command line

The '-p' argument expects an encrypted password, not an unencrypted bareword.

So you either have to encrypt the password first, or use 2 commands to add the user, the 'useradd', followed by a 'passwd' command, i.e.:

useradd username
echo unencrypted-password | passwd --stdin username

Hope this helps.
One long-haired git at your service...
Gopi Sekar
Honored Contributor

Re: creating a user account from the command line

-p option of useradd expects the encrypted password and not a plain text password. so unless you have your password in an encrypted form, -p option is not useful. login program expects the password to be in an encrypted form to validate if not, it simply rejects the login.

use passwd command to give password for a user after adding him.

Regards,
Gopi
Never Never Never Giveup
Ross Minkov
Esteemed Contributor

Re: creating a user account from the command line

When you are using "-p password" to useradd it expects the encrypted password, as returned by crypt(3). Here is one way to generate it:

# grub-md5-crypt
Password: <== type the account password here
Retype password: <== and type it again here
$1$JXyMo/$ZhK4zu4rKW9JrH83oNHJ22 <== this is the encrypted password in MD5 format

Because of the special characters that it will generate you have to single quote it when using it in useradd. For example"

# useradd -p '$1$JXyMo/$ZhK4zu4rKW9JrH83oNHJ22' account

HTH,
Ross
linuxtolinux
Frequent Advisor

Re: creating a user account from the command line

Thank you all