Shell script to add password to new user and run automatically.
I am not worried about security because this is just a basic beginners script that I am running. Using the simple and traditional commands to create a user and add to a group, then prompt for a password. I would like to be able to echo the password into the script so that it does it automatically when the script is run. So.....
useradd -N -g (group) (user) passwd (user) #This is where I would like to try to echo the password directly into the script to run automatically# Simplicity is important because Im a beginner. Thank you! |
Perhaps chpasswd would be easier to use?
http://linux.die.net/man/8/chpasswd |
I tried to add chpasswd (user)(password) after the line passwd (user) and I got a cursor that when clicked said chpasswd: Line 1 empty. Remember, I am totally new and just learning syntax and how to use options correctly. I guess I thought that there would be some kind of echo command to append to or make the passwd command read.
|
You use chpasswd instead of passwd so you would use something like:
Code:
chpasswd newuser:newpassword |
That is what I did and it didnt do anything, just gave me a solid cursor and when I hit any button I got the error
chpasswd: Line 1: missing new password Then I hit it again and it said: chpasswd: Line 2: missing new password and so on.... :( Thanks for your help, Im still googling and reading everything I can find to try to find a solution. |
Oh, sorry, you mean you want to run your script like:
Code:
./myscript username password In that case (for the password change at least) you would do something like: Code:
#!/bin/bash |
Well its a fully functioning script adding users and groups and directories and also giving permissions and all of that. The password part is just something Im trying to do so that when the script is run you dont have to type the new passwords for the users. I want it all automated. Im sorry if you dont understand what I am trying to do but I dont know how else to explain it with my limited Linux vocabulary. The chpasswd thing just isnt working when I run the script. Thank you for trying to help.
|
How about posting the script you are trying to run rather than just explaining what you're not doing? That way others can help.
|
I thought I had, atleast the only part that is involved in this question.
useradd -N -g Sales public #This is creating the user public and adding it to Sales group passwd public #This is prompting the script to ask for new password ????? #Trying to find code that automatically echos or inserts password so script doesn't ask for it. This is the best I can do since I am new on these forums and still dont know how to copy and paste my vi screen. |
So are sale sand public in the script? If so then just using chpasswd public:password ought to do it.
The use of $1 and $2 I mentioned are so that you call the script with, for example, the username and password so that you don't have to modify it every time you want to create a new user. I am confused how chpasswd username:password is is failing. |
chpasswd should work, but here's an alternative (given you're not worried about security)
Code:
for USER in john alex dave bryan sarah |
Thank you but I had to submit my assignment already. The only question I have is, is does this have to be done inside of a function? That is the only way it can read do/while and if/else statements right? I will take note of this and make a new script to try it out. Again, thank you for responding.
|
You could put it in a fn, but its not a requirement.
|
All times are GMT -5. The time now is 07:26 PM. |