Results 1 to 8 of 8
I'm trying to create a new user with a password through the command line but for some reason I can't log into the account.
Here's my stripped down command:
adduser ...
- 11-27-2007 #1Just Joined!
- Join Date
- Aug 2007
- Posts
- 33
adding users and passwords with adduser
I'm trying to create a new user with a password through the command line but for some reason I can't log into the account.
Here's my stripped down command:
adduser -p password user1
The man pages states that the password is what's returned by crypt(). Does this mean I have to call the crypt function and store the results into a variable and then pass that with the above command?
- 11-27-2007 #2forum.guy
- Join Date
- May 2004
- Location
- arch linux
- Posts
- 18,096
If you aren't sure about your command, you can just enter (as root):
...and the adduserscript will ask for the info it needs to add a new user properly. It won't allow for setting a password until all the other information is collected and you have actually created the account.Code:adduser
When all this is finished, you should be able to login as the new user.oz
→ new members/users: read this first | new member faq
→ no private messages requesting computer support - post them on the forums!
→ please use the "report post" button to alert our forum admins to problematic posts rather than responding to them yourself.
- 11-27-2007 #3Just Joined!
- Join Date
- Aug 2007
- Posts
- 33
Thanks, but I need to run this from a script file without any user input.
- 11-27-2007 #4
Here is what you can do. First read the manpage of adduser. I am pretty sure that all of these user inputs can be supplied as cmd line args (sitting on a windows machine so cant check that). Now in a plain text file put all the new user's information (one user per line, one information per column). Use awk to read this input and pass it on to adduser. You might also try perl.
- 11-27-2007 #5Just Joined!
- Join Date
- Aug 2007
- Posts
- 33
So I already have the commands down but, I just need to determine how to crypt the password. I guess my question should have really been:
How can I use the crypt function inside of my script file? The output of the crypt function is what the "-p password" switch is looking for. Since the crypt function is in a library called unistd.h. How do I get my script file to understand the crypt function?
- 11-28-2007 #6Linux User
- Join Date
- Jun 2007
- Posts
- 318
How good are you at writing Perl? That's the only way I found to encrypt a password using crypt. My knowledge of Perl is extremely limited and haven't work with it in a long time.
Perl script called a.pl to encrypt a password:
Bash script called a.bash to call a.pl and then use the encrypted password to add the account:Code:#!/usr/bin/perl my $password = 'thisisatest'; my $salt = 132; my $CryptPass = crypt($password,$salt); print $CryptPass
I don't remember how to pass parameters to Perl so you'll have to look into that.Code:#!/bin/bash -vx crypt="`./a.pl`" echo "$crypt" useradd -p "$crypt" testit
Hope this helps.
- 11-28-2007 #7Just Joined!
- Join Date
- Aug 2007
- Posts
- 33
Thanks for the input. This should do the trick...but I was wondering if there was a way were I would only have
I found that there is a function called passwd that takes the username as an arguement but, after this function call it asks the user to input the new password and then repeat the new password.
So is there any way that I can provide the passwords without having the user input them?
- 11-28-2007 #8Linux User
- Join Date
- Jun 2007
- Posts
- 318
Forgot about passwd. You'd have to write the password twice to a file like tmp.tmp and then execute the command:
Code:echo "$pswd" > tmp.tmp echo "$pswd" >> tmp.tmp passwd --stdin [username] < tmp.tmp rm -f tmp.tmp


Reply With Quote