Computer Forums

Member Login

Remember Me? Sign Up! | Forgot Password
 
Slogan
 
Closed Thread
Old 11-29-2005, 08:41 PM   #1 (permalink)
 
Newb Techie

Join Date: Dec 2004

Posts: 45

spyro187

Default Useradd script

Does anyone know of a good script that can add a single user and password. I need to pass it a username and password and have it add them automatically. The problem I am having with scripting it is that I can't figure out how to pass the password when promted.
__________________
http://www.DiscussElectronics.com
spyro187 is offline  
Old 11-29-2005, 09:04 PM   #2 (permalink)
 
Master Techie

Join Date: Apr 2004

Posts: 2,534

horndude is on a distinguished road

Default

http://home.columbus.rr.com/pedex/adduser
horndude is offline  
Old 11-29-2005, 09:17 PM   #3 (permalink)
 
Newb Techie

Join Date: Dec 2004

Posts: 45

spyro187

Default

I was reading through this and it look interactive. I need one that is not interactive. I need to pass it a username and password. Most scripts that I have found are interactive.
__________________
http://www.DiscussElectronics.com
spyro187 is offline  
Old 11-29-2005, 09:20 PM   #4 (permalink)
 
Master Techie

Join Date: Apr 2004

Posts: 2,534

horndude is on a distinguished road

Default

so take out the lines where the name and passwd are entered and set it up for a straight commandline app, its just a basic shellscript
horndude is offline  
Old 11-29-2005, 09:23 PM   #5 (permalink)
 
Master Techie

Join Date: Apr 2004

Posts: 2,534

horndude is on a distinguished road

Default

im not gonna write one for you unless you want to wait awhile

its not real hard to learn, google for "bash shell script how-to"
horndude is offline  
Old 11-29-2005, 09:36 PM   #6 (permalink)
 
Newb Techie

Join Date: Dec 2004

Posts: 45

spyro187

Default

I can script most of it. But like I was saying in the orginanl post, I can't figure out how to automatically input the password. If you use the useradd -p , it doesn't add the password. I tried to do a passwd -u $user. Which unlocks the account but the password still doesn't work. The only way I have found so far is to use an expect script. I was looking for any other ideas.
__________________
http://www.DiscussElectronics.com
spyro187 is offline  
Old 11-29-2005, 09:48 PM   #7 (permalink)
 
Master Techie

Join Date: Apr 2004

Posts: 2,534

horndude is on a distinguished road

Default

thats cause its linked against another app that does the password, so your gonna have to either copy or recreate part of the passwd app that shadows and stores the passwd or write one that does it w/o it being interactive
horndude is offline  
Old 11-29-2005, 10:07 PM   #8 (permalink)
 
Master Techie

Join Date: Apr 2004

Posts: 2,534

horndude is on a distinguished road

Default

hey spyro, get the source code for the passwd app, it should be available at any linux depository or distro website with source code, slackware.com will have it, its written in C, alter it and recompile it and rename it to something else, then use a small shell script to call that instead so you can pass the username and passwd to the new passwd app so the user's password gets shadowed and encrypted w/o it being interactive, the passwd app itself is interactive by default
horndude is offline  
Old 11-29-2005, 10:20 PM   #9 (permalink)
 
Newb Techie

Join Date: Dec 2004

Posts: 45

spyro187

Default

I can script most of it. But like I was saying in the orginanl post, I can't figure out how to automatically input the password. If you use the useradd -p , it doesn't add the password. I tried to do a passwd -u $user. Which unlocks the account but the password still doesn't work. The only way I have found so far is to use an expect script. I was looking for any other ideas.
__________________
http://www.DiscussElectronics.com
spyro187 is offline  
Old 11-29-2005, 10:26 PM   #10 (permalink)
 
Master Techie

Join Date: Apr 2004

Posts: 2,534

horndude is on a distinguished road

Default

ya, and im giving you one

goto slackware.com or the gnu/gpl website and download the C source code for the "passwd" app, change that, then recompile it, set it up to accept a password being passed to it from a shell script

on your system you have an app in /usr/bin called "passwd", its written in C, its the app that adduser uses to accept and encrypt a password is that app

it will need to be rewritten as non interactive or your not gonna be able to use the shadowed and encrypted password system on linux
horndude is offline  
 
Closed Thread

Thread Tools
Display Modes

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On