Skip to main content
deleted 204 characters in body
Source Link
Rui F Ribeiro
  • 58k
  • 28
  • 156
  • 237

Moved here from AskUbuntu

I currently have a small Ubuntu Server 12.04 machine (test environment) with about 3 non-root users created. Each user has their own public_html directory under their home...thereby allowing them to deploy multiple apps as named virtual hosts. Each user belongs to the Apache www-data group, set up as follows:

sudo usermod -a -G www-data [username]
sudo chown -R [username]:www-data /home/[username]/public_html
sudo chmod 2750 /home/[username]/public_html

Now as the root user, I am in the process of creating a bash script that will automate the creation of the folders for the VirtualHost under a prompted user's public_html as well as creating an associated entry in /etc/apache2/sites-available/. The script (run with sudo) will prompt for the user ($uzer) and the desired virtual host name ($vhost). So far after running a few checks I eventually get to the following...

mkdir -vp /home/$uzer/public_html/$vhost
mkdir -vp /home/$uzer/public_html/$vhost/www
mkdir -vp /home/$uzer/public_html/$vhost/logs
mkdir -vp /home/$uzer/public_html/$vhost/backups

I need to change the ownership of these newly created folders, so I'm unsure whether I should be doing the following:

chown -vR $uzer:www-data /home/$uzer/public_html/$vhost
chmod 2750 /home/$uzer/public_html/$vhost

My questions:

  • Is my folder structure correct/ideal?
  • I know I've used recursive (-R) option, but should I be repeating the same for $vhost/www, $vhost/logs and $vhost/backups?
  • Am I correct in thinking that the chmod above is probably redundant?
  • Is there a way I can run the mkdir commands as the user $uzer?

I am a bit of a Linux server noob, but have learned a lot in the last few months - this is probably the first shell script I've attempted to write and I still haven't fully mastered Linux permissions.

Moved here from AskUbuntu

I currently have a small Ubuntu Server 12.04 machine (test environment) with about 3 non-root users created. Each user has their own public_html directory under their home...thereby allowing them to deploy multiple apps as named virtual hosts. Each user belongs to the Apache www-data group, set up as follows:

sudo usermod -a -G www-data [username]
sudo chown -R [username]:www-data /home/[username]/public_html
sudo chmod 2750 /home/[username]/public_html

Now as the root user, I am in the process of creating a bash script that will automate the creation of the folders for the VirtualHost under a prompted user's public_html as well as creating an associated entry in /etc/apache2/sites-available/. The script (run with sudo) will prompt for the user ($uzer) and the desired virtual host name ($vhost). So far after running a few checks I eventually get to the following...

mkdir -vp /home/$uzer/public_html/$vhost
mkdir -vp /home/$uzer/public_html/$vhost/www
mkdir -vp /home/$uzer/public_html/$vhost/logs
mkdir -vp /home/$uzer/public_html/$vhost/backups

I need to change the ownership of these newly created folders, so I'm unsure whether I should be doing the following:

chown -vR $uzer:www-data /home/$uzer/public_html/$vhost
chmod 2750 /home/$uzer/public_html/$vhost

My questions:

  • Is my folder structure correct/ideal?
  • I know I've used recursive (-R) option, but should I be repeating the same for $vhost/www, $vhost/logs and $vhost/backups?
  • Am I correct in thinking that the chmod above is probably redundant?
  • Is there a way I can run the mkdir commands as the user $uzer?

I am a bit of a Linux server noob, but have learned a lot in the last few months - this is probably the first shell script I've attempted to write and I still haven't fully mastered Linux permissions.

I currently have a small Ubuntu Server 12.04 machine (test environment) with about 3 non-root users created. Each user has their own public_html directory under their home...thereby allowing them to deploy multiple apps as named virtual hosts. Each user belongs to the Apache www-data group, set up as follows:

sudo usermod -a -G www-data [username]
sudo chown -R [username]:www-data /home/[username]/public_html
sudo chmod 2750 /home/[username]/public_html

Now as the root user, I am in the process of creating a bash script that will automate the creation of the folders for the VirtualHost under a prompted user's public_html as well as creating an associated entry in /etc/apache2/sites-available/. The script (run with sudo) will prompt for the user ($uzer) and the desired virtual host name ($vhost). So far after running a few checks I eventually get to the following...

mkdir -vp /home/$uzer/public_html/$vhost
mkdir -vp /home/$uzer/public_html/$vhost/www
mkdir -vp /home/$uzer/public_html/$vhost/logs
mkdir -vp /home/$uzer/public_html/$vhost/backups

I need to change the ownership of these newly created folders, so I'm unsure whether I should be doing the following:

chown -vR $uzer:www-data /home/$uzer/public_html/$vhost
chmod 2750 /home/$uzer/public_html/$vhost

My questions:

  • Is my folder structure correct/ideal?
  • I know I've used recursive (-R) option, but should I be repeating the same for $vhost/www, $vhost/logs and $vhost/backups?
  • Am I correct in thinking that the chmod above is probably redundant?
  • Is there a way I can run the mkdir commands as the user $uzer?
replaced http://askubuntu.com/ with https://askubuntu.com/
Source Link

Moved here from AskUbuntuAskUbuntu

I currently have a small Ubuntu Server 12.04 machine (test environment) with about 3 non-root users created. Each user has their own public_html directory under their home...thereby allowing them to deploy multiple apps as named virtual hosts. Each user belongs to the Apache www-data group, set up as follows:

sudo usermod -a -G www-data [username]
sudo chown -R [username]:www-data /home/[username]/public_html
sudo chmod 2750 /home/[username]/public_html

Now as the root user, I am in the process of creating a bash script that will automate the creation of the folders for the VirtualHost under a prompted user's public_html as well as creating an associated entry in /etc/apache2/sites-available/. The script (run with sudo) will prompt for the user ($uzer) and the desired virtual host name ($vhost). So far after running a few checks I eventually get to the following...

mkdir -vp /home/$uzer/public_html/$vhost
mkdir -vp /home/$uzer/public_html/$vhost/www
mkdir -vp /home/$uzer/public_html/$vhost/logs
mkdir -vp /home/$uzer/public_html/$vhost/backups

I need to change the ownership of these newly created folders, so I'm unsure whether I should be doing the following:

chown -vR $uzer:www-data /home/$uzer/public_html/$vhost
chmod 2750 /home/$uzer/public_html/$vhost

My questions:

  • Is my folder structure correct/ideal?
  • I know I've used recursive (-R) option, but should I be repeating the same for $vhost/www, $vhost/logs and $vhost/backups?
  • Am I correct in thinking that the chmod above is probably redundant?
  • Is there a way I can run the mkdir commands as the user $uzer?

I am a bit of a Linux server noob, but have learned a lot in the last few months - this is probably the first shell script I've attempted to write and I still haven't fully mastered Linux permissions.

Moved here from AskUbuntu

I currently have a small Ubuntu Server 12.04 machine (test environment) with about 3 non-root users created. Each user has their own public_html directory under their home...thereby allowing them to deploy multiple apps as named virtual hosts. Each user belongs to the Apache www-data group, set up as follows:

sudo usermod -a -G www-data [username]
sudo chown -R [username]:www-data /home/[username]/public_html
sudo chmod 2750 /home/[username]/public_html

Now as the root user, I am in the process of creating a bash script that will automate the creation of the folders for the VirtualHost under a prompted user's public_html as well as creating an associated entry in /etc/apache2/sites-available/. The script (run with sudo) will prompt for the user ($uzer) and the desired virtual host name ($vhost). So far after running a few checks I eventually get to the following...

mkdir -vp /home/$uzer/public_html/$vhost
mkdir -vp /home/$uzer/public_html/$vhost/www
mkdir -vp /home/$uzer/public_html/$vhost/logs
mkdir -vp /home/$uzer/public_html/$vhost/backups

I need to change the ownership of these newly created folders, so I'm unsure whether I should be doing the following:

chown -vR $uzer:www-data /home/$uzer/public_html/$vhost
chmod 2750 /home/$uzer/public_html/$vhost

My questions:

  • Is my folder structure correct/ideal?
  • I know I've used recursive (-R) option, but should I be repeating the same for $vhost/www, $vhost/logs and $vhost/backups?
  • Am I correct in thinking that the chmod above is probably redundant?
  • Is there a way I can run the mkdir commands as the user $uzer?

I am a bit of a Linux server noob, but have learned a lot in the last few months - this is probably the first shell script I've attempted to write and I still haven't fully mastered Linux permissions.

Moved here from AskUbuntu

I currently have a small Ubuntu Server 12.04 machine (test environment) with about 3 non-root users created. Each user has their own public_html directory under their home...thereby allowing them to deploy multiple apps as named virtual hosts. Each user belongs to the Apache www-data group, set up as follows:

sudo usermod -a -G www-data [username]
sudo chown -R [username]:www-data /home/[username]/public_html
sudo chmod 2750 /home/[username]/public_html

Now as the root user, I am in the process of creating a bash script that will automate the creation of the folders for the VirtualHost under a prompted user's public_html as well as creating an associated entry in /etc/apache2/sites-available/. The script (run with sudo) will prompt for the user ($uzer) and the desired virtual host name ($vhost). So far after running a few checks I eventually get to the following...

mkdir -vp /home/$uzer/public_html/$vhost
mkdir -vp /home/$uzer/public_html/$vhost/www
mkdir -vp /home/$uzer/public_html/$vhost/logs
mkdir -vp /home/$uzer/public_html/$vhost/backups

I need to change the ownership of these newly created folders, so I'm unsure whether I should be doing the following:

chown -vR $uzer:www-data /home/$uzer/public_html/$vhost
chmod 2750 /home/$uzer/public_html/$vhost

My questions:

  • Is my folder structure correct/ideal?
  • I know I've used recursive (-R) option, but should I be repeating the same for $vhost/www, $vhost/logs and $vhost/backups?
  • Am I correct in thinking that the chmod above is probably redundant?
  • Is there a way I can run the mkdir commands as the user $uzer?

I am a bit of a Linux server noob, but have learned a lot in the last few months - this is probably the first shell script I've attempted to write and I still haven't fully mastered Linux permissions.

edited tags; edited title
Link
Jeff Schaller
  • 68.8k
  • 35
  • 122
  • 264

Ubuntu Bash - Changing permissions toon user files for automating Apache VirtualHost creation

thanks-appreciate deleted
Source Link
Anthon
  • 81.4k
  • 42
  • 174
  • 228
Loading
Source Link
maGz
  • 993
  • 2
  • 10
  • 20
Loading