Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

In Ubuntu 12.04, I'm having difficulties creating a script (since I'm not experienced with it), and is assigned to add multiple users from a list of names in file usernames.txt.

  1. The users will have url: hxxp://hostname/~userN, where N is integer.
  2. The users can SSH with password which is the same with the username.
  3. The users will have file /home/userN/public_html/index.html consist of text: Hello userN
  4. The users also have a database with name & password is userN.

I have configured apache userdir, mysql. Thanks for any helps...

share|improve this question
up vote 1 down vote accepted

echo '[mysql]' > ~/.my.cnf
echo -e 'user\t\t= root' >> ~/.my.cnf
echo -e 'password\t= <root password>' >> ~/.my.cnf

while read u; do 
    # 1. config in Apache

    # 2. DON'T DO THIS. Why do you want to give ssh access to these users?
    /usr/sbin/useradd -m -p $(perl -e 'print crypt($ARGV[0], "password")' $u) $u

    # 3. Check to see if `public_html` directory exist
    [ ! -d /home/$u/public_html ] && mkdir /home/$u/public_html
    echo 'Hello '$u > /home/$u/public_html/index.html

    # 4. Make sure that you can login to MySQL without prompting for password
    mysql -e "create database $u; grant all privileges on $u.* to $u@'localhost' identified by '$u';"
done < usernames.txt
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.