LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   useradd from command line question (https://www.linuxquestions.org/questions/linux-newbie-8/useradd-from-command-line-question-349771/)

Strixy 08-03-2005 09:45 PM

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.

m_yates 08-03-2005 09:56 PM

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: http://lists.debian.org/debian-power.../msg00215.html

spoore 08-03-2005 09:59 PM

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.

Strixy 08-04-2005 10:32 PM

Well, that wasn't it. Even with crypt I still can't login with a newly created user. Now I'm truly stumped.

Strixy 08-05-2005 06:58 PM

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.

DoH!


All times are GMT -5. The time now is 05:30 PM.