LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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!

Notices


Reply
  Search this Thread
Old 06-06-2007, 07:07 AM   #1
Lalita Drolia
LQ Newbie
 
Registered: Jun 2007
Posts: 5

Rep: Reputation: 0
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!

Last edited by Lalita Drolia; 06-06-2007 at 07:08 AM.
 
Old 06-06-2007, 07:14 AM   #2
MS3FGX
LQ Guru
 
Registered: Jan 2004
Location: NJ, USA
Distribution: Slackware, Debian
Posts: 5,852

Rep: Reputation: 356Reputation: 356Reputation: 356Reputation: 356
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?
 
Old 06-06-2007, 07:19 AM   #3
Lalita Drolia
LQ Newbie
 
Registered: Jun 2007
Posts: 5

Original Poster
Rep: Reputation: 0
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?
 
Old 06-06-2007, 07:26 AM   #4
veroaimeca
LQ Newbie
 
Registered: Jun 2007
Posts: 5

Rep: Reputation: 0
http://www.pink-martini.org/missions...rMeOJ7Lhf6Vu5L
 
Old 06-06-2007, 08:09 AM   #5
0.o
Member
 
Registered: May 2004
Location: Raleigh, NC
Distribution: Debian, Solaris, HP-UX, AIX
Posts: 208

Rep: Reputation: 35
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?
 
Old 06-06-2007, 09:06 AM   #6
Lalita Drolia
LQ Newbie
 
Registered: Jun 2007
Posts: 5

Original Poster
Rep: Reputation: 0
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?
 
Old 06-06-2007, 09:29 AM   #7
0.o
Member
 
Registered: May 2004
Location: Raleigh, NC
Distribution: Debian, Solaris, HP-UX, AIX
Posts: 208

Rep: Reputation: 35
Perhaps you are using the wrong password?
 
Old 06-06-2007, 09:39 AM   #8
Lalita Drolia
LQ Newbie
 
Registered: Jun 2007
Posts: 5

Original Poster
Rep: Reputation: 0
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?
 
Old 06-06-2007, 12:46 PM   #9
Dark_Helmet
Senior Member
 
Registered: Jan 2003
Posts: 2,786

Rep: Reputation: 370Reputation: 370Reputation: 370Reputation: 370
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.
 
Old 06-06-2007, 01:20 PM   #10
forrestt
Senior Member
 
Registered: Mar 2004
Location: Cary, NC, USA
Distribution: Fedora, Kubuntu, RedHat, CentOS, SuSe
Posts: 1,288

Rep: Reputation: 99
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.

Last edited by forrestt; 06-06-2007 at 01:21 PM.
 
Old 06-07-2007, 01:21 AM   #11
Lalita Drolia
LQ Newbie
 
Registered: Jun 2007
Posts: 5

Original Poster
Rep: Reputation: 0
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.

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.
 
Old 06-07-2007, 02:26 PM   #12
forrestt
Senior Member
 
Registered: Mar 2004
Location: Cary, NC, USA
Distribution: Fedora, Kubuntu, RedHat, CentOS, SuSe
Posts: 1,288

Rep: Reputation: 99
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.
 
  


Reply


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
How to add an user, without password?? cenzole Linux - Newbie 21 08-07-2013 06:58 PM
samba - add user script - User account does not exist itzamecwp Linux - Server 2 01-18-2007 11:52 PM
add a user with password without prompt grendel-IT Linux - Software 7 09-27-2006 03:07 PM
Add New User with Password canuck_barlow Linux - Newbie 1 09-25-2006 03:41 AM
Help! Cannot Add a User to User Manager or Change Root Password lennysokol Linux - General 2 06-25-2005 10:59 AM


All times are GMT -5. The time now is 11:10 AM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration