LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware
User Name
Password
Slackware This Forum is for the discussion of Slackware Linux.

Notices


Reply
  Search this Thread
Old 05-10-2010, 02:49 PM   #1
lucmove
Senior Member
 
Registered: Aug 2005
Location: Brazil
Distribution: Debian
Posts: 1,433

Rep: Reputation: 110Reputation: 110
I can't make 'useradd' work


Code:
useradd -u 8001 -g luc -p mypassword -s /usr/bin/bash -d /home/luc luc
Open another terminal:
Code:
luc[159-0]test> ssh luc@61.62.63.64
luc@61.62.63.64's password:
Permission denied, please try again.
luc@61.62.63.64's password:
Permission denied, please try again.
luc@61.62.63.64's password:
Permission denied (publickey,password,keyboard-interactive).
Try again:
# userdel luc
# adduser
(answer all the questions...)

Jump back to the other terminal... Try SSH login... Success!

'adduser' works, 'useradd' doesn't. Why? I have read the man pages several times and can't find the error in my command line.

I have a similar problem with groupadd

This fails:
groupadd -g 8001 staff

This works:
groupadd staff

why?!

TIA
 
Old 05-10-2010, 02:52 PM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
-p takes an encrypted password, not a plaintext passwd. It needs to be the exact md5 / sha hash that goes into /etc/shadow.
 
1 members found this post helpful.
Old 05-10-2010, 09:09 PM   #3
lucmove
Senior Member
 
Registered: Aug 2005
Location: Brazil
Distribution: Debian
Posts: 1,433

Original Poster
Rep: Reputation: 110Reputation: 110
Do you know how I can obtain that hash? I really wish I could automate this entire procedure...

'man useradd' says that -p specifies "the encrypted password, as returned by crypt(3)." There is no 'crypt' command or package, neither on Ubuntu nor on Slackware. I assume some other package or library provides that command, but the man page won't say what it is. That would be too helpful for a man page, which must be against the rules or something.
 
Old 05-10-2010, 09:24 PM   #4
custangro
Senior Member
 
Registered: Nov 2006
Location: California
Distribution: Fedora , CentOS , RHEL
Posts: 1,979
Blog Entries: 1

Rep: Reputation: 209Reputation: 209Reputation: 209
Quote:
Originally Posted by lucmove View Post
Do you know how I can obtain that hash? I really wish I could automate this entire procedure...

'man useradd' says that -p specifies "the encrypted password, as returned by crypt(3)." There is no 'crypt' command or package, neither on Ubuntu nor on Slackware. I assume some other package or library provides that command, but the man page won't say what it is. That would be too helpful for a man page, which must be against the rules or something.
mcrypt is the Linux version of crypt ...

You can also do...

Code:
root@host# echo "password" ¦ md5sum
To get the hash...there is also a sha1sum command as well
 
Old 05-11-2010, 09:11 PM   #5
lucmove
Senior Member
 
Registered: Aug 2005
Location: Brazil
Distribution: Debian
Posts: 1,433

Original Poster
Rep: Reputation: 110Reputation: 110
Well, I'm trying to get by on my own but haven't made much progress. To wit:

- I created the account with adduser, which works, then I checked what the encrypted password is in /etc/shadow. Then I ran echo "password" ¦ md5sum like you suggested. In fact, I tried that long before I got your reply. The output of that command does not match the encrypted password in /etc/shadow. I didn't try just md5sum, I also tried it with shasum, sha1sum, and all the other sha[1-9]*sum commands I have here, for good measure. None of those output the same encrypted password I have in /etc/shadow.

- I downloaded the mcrypt package, so now I have the mcrypt command. But I can't figure out how to use it to obtain the same encrypted password I can use in /etc/shadow. Mcrypt, in good Linux tradition, makes the whole task at hand a lot more difficult than it could have been. It refuses to output to the terminal so I can see the darn output and compare with the encrypted password I already have. So I redirect it to a file, which turns out to be binary and gets all garbled with 'cat'.

Can someone please enlighten me? This is getting really tiresome. I just want to use one damn option in one damn command, I am sick of going through all this trouble because of one line in my 80-line script.

TIA
 
Old 05-11-2010, 09:56 PM   #6
bgeddy
Senior Member
 
Registered: Sep 2006
Location: Liverpool - England
Distribution: slackware64 13.37 and -current, Dragonfly BSD
Posts: 1,810

Rep: Reputation: 232Reputation: 232Reputation: 232
I'm not sure about getting the crypt() result of a password but how about a workaround. Just create your user without supplying the password then add a line to the script to change the password like this :
Code:
useradd -u 8001 -g luc -s /usr/bin/bash -d /home/luc luc
echo "luc:mypassword" | chpasswd
That will do the same as your original one liner adding the user and adding the password.
 
1 members found this post helpful.
Old 05-11-2010, 10:12 PM   #7
custangro
Senior Member
 
Registered: Nov 2006
Location: California
Distribution: Fedora , CentOS , RHEL
Posts: 1,979
Blog Entries: 1

Rep: Reputation: 209Reputation: 209Reputation: 209
Quote:
Originally Posted by lucmove View Post
Well, I'm trying to get by on my own but haven't made much progress. To wit:

- I created the account with adduser, which works, then I checked what the encrypted password is in /etc/shadow. Then I ran echo "password" ¦ md5sum like you suggested. In fact, I tried that long before I got your reply. The output of that command does not match the encrypted password in /etc/shadow. I didn't try just md5sum, I also tried it with shasum, sha1sum, and all the other sha[1-9]*sum commands I have here, for good measure. None of those output the same encrypted password I have in /etc/shadow.

- I downloaded the mcrypt package, so now I have the mcrypt command. But I can't figure out how to use it to obtain the same encrypted password I can use in /etc/shadow. Mcrypt, in good Linux tradition, makes the whole task at hand a lot more difficult than it could have been. It refuses to output to the terminal so I can see the darn output and compare with the encrypted password I already have. So I redirect it to a file, which turns out to be binary and gets all garbled with 'cat'.

Can someone please enlighten me? This is getting really tiresome. I just want to use one damn option in one damn command, I am sick of going through all this trouble because of one line in my 80-line script.

TIA
instead of trying to pass the -p to the useradd command...why don't you add one more line to your 80 line script?

Code:
echo "password" ¦ passwd --stdin username
Just a thought
 
1 members found this post helpful.
Old 05-11-2010, 11:44 PM   #8
Richard Cranium
Senior Member
 
Registered: Apr 2009
Location: McKinney, Texas
Distribution: Slackware64 15.0
Posts: 3,858

Rep: Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225
Quote:
Originally Posted by lucmove View Post
Well, I'm trying to get by on my own but haven't made much progress. To wit:

- I created the account with adduser, which works, then I checked what the encrypted password is in /etc/shadow. Then I ran echo "password" ¦ md5sum like you suggested. In fact, I tried that long before I got your reply. The output of that command does not match the encrypted password in /etc/shadow. I didn't try just md5sum, I also tried it with shasum, sha1sum, and all the other sha[1-9]*sum commands I have here, for good measure. None of those output the same encrypted password I have in /etc/shadow.

- I downloaded the mcrypt package, so now I have the mcrypt command. But I can't figure out how to use it to obtain the same encrypted password I can use in /etc/shadow. Mcrypt, in good Linux tradition, makes the whole task at hand a lot more difficult than it could have been. It refuses to output to the terminal so I can see the darn output and compare with the encrypted password I already have. So I redirect it to a file, which turns out to be binary and gets all garbled with 'cat'.

Can someone please enlighten me? This is getting really tiresome. I just want to use one damn option in one damn command, I am sick of going through all this trouble because of one line in my 80-line script.

TIA
"man 3 crypt" tells you how the password is generated. It isn't an md5 hash of the input string.
 
Old 05-12-2010, 09:55 AM   #9
bgeddy
Senior Member
 
Registered: Sep 2006
Location: Liverpool - England
Distribution: slackware64 13.37 and -current, Dragonfly BSD
Posts: 1,810

Rep: Reputation: 232Reputation: 232Reputation: 232
Quote:
Do you know how I can obtain that hash? I really wish I could automate this entire procedure...
I have been looking into the crypt function and have made a little python script that takes the password as a command line argument and returns the encrypted password. Here it is:-
Code:
#!/usr/bin/python
import sys,crypt,random,string
def salt(chars = string.letters + string.digits):
        return random.choice(chars) + random.choice(chars)

if len(sys.argv) != 2:
        print "Error in command line"
        exit(1)
print crypt.crypt(sys.argv[1],salt())
If you create a script file with this, for example tpwd.py, and make it executable you may run your original one liner to add a user, (from the directory tpwd.py is in), like this :
Code:
useradd -u 8001 -g luc -p $(./tpwd.py mypassword) -s /usr/bin/bash -d /home/luc luc
and the user will be created with the supplied password.
 
Old 05-12-2010, 10:50 AM   #10
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
well you can use the chpasswd tool to do this seperately, which does take in a plain text password. You can also feed chpasswd a single file / stdin stream of user:password lines and it'll do them all in one go.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
make Xconfig doesn't work, make menuconfig does work Debian/KDE bucovaina78 Linux - Kernel 1 10-15-2008 01:26 PM
1st time installing redhat - Make and Make Install does not work runlikeanantelope Linux - Newbie 4 02-19-2007 03:58 PM
Useradd - Cannot locate /etc/default/useradd in Solaris Paean Solaris / OpenSolaris 4 12-09-2005 01:36 AM
2 things: startx and useradd don't work ckent47 Linux - Software 4 08-27-2005 06:07 PM
Fedora - adduser/useradd doesn't work chongluo Linux - Newbie 2 03-25-2004 03:59 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware

All times are GMT -5. The time now is 04:23 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration