LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-16-2003, 06:34 AM   #1
mtest
LQ Newbie
 
Registered: Oct 2003
Location: India
Posts: 22

Rep: Reputation: 15
how to assign password for a user in shell script


The problem is to create a user and assign a password for that user from the shell script instead of at prompt.
when i create a shell file
and i have typed
useradd xyz
passwd xyz pqr
and when i run the shell by giving bash file name, the new user is created but the password is not assigned, it is treating pqr is also a username

please tell me how to assign password for a user from the shell script

thanks in Advance

Last edited by mtest; 10-16-2003 at 06:50 AM.
 
Old 10-16-2003, 06:40 AM   #2
Tarts
Member
 
Registered: Feb 2003
Distribution: Slackware 9.1 (exclusively) ;)
Posts: 344

Rep: Reputation: 30
You can't. There's no way to do that using an unaltered 'adduser' within a bash script.

Tarts


{edit}

Last edited by Tarts; 10-16-2003 at 06:59 AM.
 
Old 10-16-2003, 07:05 AM   #3
Tarts
Member
 
Registered: Feb 2003
Distribution: Slackware 9.1 (exclusively) ;)
Posts: 344

Rep: Reputation: 30
You learn something new everyday:
Code:
#!/bin/bash
useradd -p <password> <username>
 
Old 10-16-2003, 07:44 AM   #4
mtest
LQ Newbie
 
Registered: Oct 2003
Location: India
Posts: 22

Original Poster
Rep: Reputation: 15
How to assign password for user in shell script

I tried executing

useradd -p <password> <username>

but it doesn't work.

please reply
 
Old 10-16-2003, 07:48 AM   #5
Tarts
Member
 
Registered: Feb 2003
Distribution: Slackware 9.1 (exclusively) ;)
Posts: 344

Rep: Reputation: 30
Re: How to assign password for user in shell script

Quote:
Originally posted by mtest
I tried executing

useradd -p <password> <username>

but it doesn't work.

please reply
You need to replace '<password>' with the password to be used, and the <username> with the username to be used.

Code:
#!/bin/bash
useradd -p 'G7*h!&dW@' mtest
Be sure to put strong quotes '' around the password.
Tarts

Last edited by Tarts; 10-16-2003 at 07:52 AM.
 
Old 10-16-2003, 08:10 AM   #6
mtest
LQ Newbie
 
Registered: Oct 2003
Location: India
Posts: 22

Original Poster
Rep: Reputation: 15
I tried same thing which you have mentioned, it doesnt show error at $prompt, when I try login with username(mtest) and when I enter the paswword in the password window. it is not allowing to login. but user is cerated without password,( I tried as root to assign, it that user(mtest )already exists).
 
Old 10-16-2003, 09:30 AM   #7
Tarts
Member
 
Registered: Feb 2003
Distribution: Slackware 9.1 (exclusively) ;)
Posts: 344

Rep: Reputation: 30
I can't get 'useradd' to encrypt the password, whatever password you enter can be seen literally when you open '/etc/shadow'....This mean's that 'login' would encyrpt it, and the password would never be right, I guess this program just doesn't work as specified yet, mabey somebody should work on it.

Tarts
 
Old 10-16-2003, 11:04 AM   #8
Tarts
Member
 
Registered: Feb 2003
Distribution: Slackware 9.1 (exclusively) ;)
Posts: 344

Rep: Reputation: 30
Talking

http://www.cpqlinux.com/ks-useradd.html
I wrote the script, but got the idea from the site above in which I learned about 'openssl'.

Code:
#!/bin/bash
#enter password and username [adduser.sh '<password>' <username>]
PASS=$(openssl passwd -1 "$1")

useradd -p "$PASS" "$2"
exit 0

Last edited by Tarts; 10-16-2003 at 01:35 PM.
 
Old 10-17-2003, 02:32 AM   #9
mtest
LQ Newbie
 
Registered: Oct 2003
Location: India
Posts: 22

Original Poster
Rep: Reputation: 15
Thanks Mr Tarts. It is working well.
U have done a great job to me. It is very much worth for me. I am in the mid of project . If any doubts can i contact u. pls give me ur mail id
Thank u very much
 
Old 10-17-2003, 04:27 AM   #10
Tarts
Member
 
Registered: Feb 2003
Distribution: Slackware 9.1 (exclusively) ;)
Posts: 344

Rep: Reputation: 30
Quote:
Originally posted by mtest
Thanks Mr Tarts. It is working well.
U have done a great job to me. It is very much worth for me. I am in the mid of project . If any doubts can i contact u. pls give me ur mail id
Thank u very much
E-mail me from the link's at the bottom of my post, although, I don't know how much help i'll be.

Tarts
 
Old 10-29-2003, 06:52 AM   #11
macie
Member
 
Registered: Oct 2003
Location: /dev/null
Posts: 33

Rep: Reputation: 15
hey

this posted helped me alot.. thx..


 
  


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
Shell script to change password kamal_aitin Linux - General 6 07-25-2007 12:09 AM
Can't assign password to user corbis_demon Linux - General 2 02-22-2005 07:46 AM
Shell Script For Password cpope67 Programming 4 01-10-2005 02:16 AM
Password Shell Script Solaris 9 cpope67 Solaris / OpenSolaris 1 12-30-2004 03:15 PM
how can you assign a password to a new user want2learn Linux - Security 2 09-30-2004 07:50 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:59 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
Open Source Consulting | Domain Registration