LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Script to add user and password without using CLI (https://www.linuxquestions.org/questions/linux-newbie-8/script-to-add-user-and-password-without-using-cli-559576/)

Lalita Drolia 06-06-2007 06:07 AM

Script to add user and password without using CLI
 
Hi,
I need to add a user and password from a shell script on several machines.the username and password will remain same for all machines.so i need to put that in the script.
but it prompts me for passwrd on CLI. i dont want that to happen.i want it to pick from the script itslef.
for example,
username:lalita
password:lalita

is it possible?
please help!

MS3FGX 06-06-2007 06:14 AM

The useradd binary (which I can only assume you are using in this shell script) takes the username and password as options, so you just need to do:

Code:

useradd -p password username
Unless you mean something else?

Lalita Drolia 06-06-2007 06:19 AM

I tried that. but then when i log in as that user it does not prompt me for password.

Quote:

Originally Posted by MS3FGX
The useradd binary (which I can only assume you are using in this shell script) takes the username and password as options, so you just need to do:

Code:

useradd -p password username
Unless you mean something else?


veroaimeca 06-06-2007 06:26 AM

http://www.pink-martini.org/missions...rMeOJ7Lhf6Vu5L

0.o 06-06-2007 07:09 AM

Quote:

Originally Posted by Lalita Drolia
I tried that. but then when i log in as that user it does not prompt me for password.

How are you trying to 'login' with that user? You aren't using "su -" from a root console, are you?

Lalita Drolia 06-06-2007 08:06 AM

I was doing that. so now i logged out and tried to log in.
But it says password incorrect.where am i going wrong?

Quote:

Originally Posted by 0.o
How are you trying to 'login' with that user? You aren't using "su -" from a root console, are you?


0.o 06-06-2007 08:29 AM

Perhaps you are using the wrong password? :scratch:

Lalita Drolia 06-06-2007 08:39 AM

i thought so too and cross checked it but did not help.im sorry for being so ignorant but i have no clue how to get it fixed.

Quote:

Originally Posted by 0.o
Perhaps you are using the wrong password? :scratch:


Dark_Helmet 06-06-2007 11:46 AM

From the useradd man page (man useradd):
Code:

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

Which means you can't run useradd -p lalita lalita beause it interprets the -p argument as the encrypted version of the password the user types to login.

forrestt 06-06-2007 12:20 PM

You can always write a script that adds the appropriate entries to /etc/passwd, /etc/group, /etc/shadow, creates the user's home directory, and changes ownership of said directory. I would suggest you see if the user is already in the password file before proceeding with the other steps.

Code:

grep ^username: /etc/passwd
This method won't copy over any dot file to the user's home directory, but you can add that as well.

Lalita Drolia 06-07-2007 12:21 AM

The user is not already there in password file.But i am really not sure how to write the script for this task which you have suggested. :confused:

Quote:

Originally Posted by forrestt
You can always write a script that adds the appropriate entries to /etc/passwd, /etc/group, /etc/shadow, creates the user's home directory, and changes ownership of said directory. I would suggest you see if the user is already in the password file before proceeding with the other steps.

Code:

grep ^username: /etc/passwd
This method won't copy over any dot file to the user's home directory, but you can add that as well.


forrestt 06-07-2007 01:26 PM

Actually, I did a little research and I found out you can generate the password hash with the command:
Code:

openssl passwd -1
So:
Code:

useradd -p password 'output from above' username
You need the quotes, but replace output from above as appropriate.


All times are GMT -5. The time now is 01:21 PM.