cooper549 Posted March 30, 2016 Posted March 30, 2016 Hi I'm fairly new on edugeek however I've been here before with some programming woes a while back and hoping someone can aid me again. Ive been asked to look into some of the questions for a controlled assessment to clarify how they could be accomplished and although I've used linux enough before, I've hit a brick wall when it comes to completing one question relating to scripts. The question asks to create a bash script for creating users and adding them to groups and I've looked around online for numerous different ways to accomplish this but I'm finding myself more confused by the many different methods used. If someone is able to explain and help regarding this and help give examples with possibly with commented code so I can understand the process. I'll Have a better chance of explaining it to our Computing Teacher who is completely new to linux. Im open to options and if anyone is available to help, it would be greatly appreciated. Thanks Adam
pcstru Posted March 30, 2016 Posted March 30, 2016 #!/bin/bash LOGF="./bulkuseradd.log" USERLIST="./userlist" echo "-------------------------------------------------------------------------- ------" >> $LOGF ; date >> $LOGF; echo "-------------------------------------------------------------------------- ------" >> $LOGF ; while read USER; do PASS=$(tr -dc _A-Z-a-z-0-9 # unix account # see -g and -G options to handle groups, see also usermod # new account is disabled by default; see man useradd # useradd -s /bin/false $USER ## alt: enabled unix account with password: EncryptedPASS=$( mkpasswd --hash=md5 $PASS ) sudo useradd -b /home -d /home/$USER -s /bin/bash -m -p $EncryptedPASS $ USER sudo mkdir /home/$USER/public_html sudo chmod 755 /home/$USER/public_html sudo chown $USER:$USER /home/$USER/public_html # output so you can tell users their password echo $USER $PASS; echo ; echo $USER $PASS >> $LOGF; echo >> $LOGF ; done < $USERLIST echo >> $LOGF; This is a bash script for an ubuntu LAMPS server to create users from a list of names supplied in a file (one username per line). The main loop processes one line at a time, generates a password, encrypts it and then runs commands to add the user, set up the home directory and directories for local user access via apache (the /~name thing). It then spits the info into a log file to send to the teacher.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now