Shell script to add password to new user and run automatically.
Linux - NewbieThis 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
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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!
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.
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.
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.
Distribution: Debian Sid AMD64, Raspbian Wheezy, various VMs
Posts: 7,680
Rep:
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.
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.