Review your favorite Linux distribution.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 08-03-2005, 10:45 PM   #1
Registered: Apr 2004
Location: Nowhere, Oblivion
Distribution: Ubuntu
Posts: 48

Rep: Reputation: 15
useradd from script question

I can create a new account using useradd and everything is fine (all files and dir's are created), but if I try to login as that user I cannot.

the exact line I am running is

sudo useradd -p password -g usergroup newuser

This doesn't seem to work.

However, if I use the GUI to add a user all works out just fine. Also, if I add a user without using the -p switch and manually enter the password at the prompt it works.

I have a sneaking suspicion that I am doing something wrong with the -p switch.

Reading the man pages (and searching the net to find more copies of the man page, arrgh) I have tripped over a troubling quote that I was hoping someone would be able to interpret for me.

"-p passwd
The encrypted password, as returned by crypt(3). The default is to disable the account."

"as returned by crypt"

If I want to include -p as a switch do I first have to run crypt? if so, can I pass a variable to useradd from inside a script?

You see, I'm trying to run useradd from a script. (maintence shortcut)

Why do I post these things when 1/2 way through I figure out the answer or at least something else to try.

Why am I even posting this?

Ah yes, just in case someone else needs an answer to this question I suppose or if someone knows of a better option, or if this idea doesn't work I've already posted the problem.

I'll be back with a report either way. Thank you for your ideas.

Last edited by Strixy; 08-04-2005 at 11:41 PM.
Old 08-03-2005, 10:56 PM   #2
Senior Member
Registered: Aug 2003
Location: Upstate
Distribution: Debian, Mint, Mythbuntu
Posts: 1,210

Rep: Reputation: 71
On Debian-based systems, you can use "adduser" instead of useradd. I do not know if it will make it anu easier to get your script working. This list posting describes the differences between adduser and useradd:
Old 08-03-2005, 10:59 PM   #3
LQ Newbie
Registered: Aug 2004
Posts: 23

Rep: Reputation: 2
At least with some distributions, useradd expects the encrypted passwd with the "-p" flag. I usually just run useradd without -p and then run "passwd username" as root after to set the password. You could also get the encrypted version of the password before running useradd and then use that string with the -p flag I think.
Old 08-04-2005, 11:32 PM   #4
Registered: Apr 2004
Location: Nowhere, Oblivion
Distribution: Ubuntu
Posts: 48

Original Poster
Rep: Reputation: 15
Well, that wasn't it. Even with crypt I still can't login with a newly created user. Now I'm truly stumped.
Old 08-05-2005, 07:58 PM   #5
Registered: Apr 2004
Location: Nowhere, Oblivion
Distribution: Ubuntu
Posts: 48

Original Poster
Rep: Reputation: 15
Got it.

My problem?

There are TWO 'S' characters at the end of $pass

I'm going to go and crawl into a corner and smack my forehead repeatedly.



Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Command line question shadoweyez Linux - Software 2 11-18-2005 07:28 PM
Command line question satimis Linux - General 14 06-20-2005 10:46 PM
command line question phonecian Linux - Software 2 10-09-2004 09:36 AM
useradd command question hct224 Linux - Newbie 2 06-14-2004 05:47 PM
command line question... warheros Linux - Newbie 12 06-25-2003 05:34 AM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 06:56 PM.

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