4

I am a web developer and have Apache setup on my local system for testing.

I keep running into issues with the permissions e.g. unless I chmod any new directories to 777 my IDE cannot write to the files there.

I was hoping there was a way to add myself to the group that has control of the www folder (and any sub folders) so I do not have to chmod the files every time.

4 Answers 4

5

I am working on a related issue, but in your case, you could just add yourself to the web group

sudo adduser $USER www-data

replace USER$ with your username of course. www-data is the group used for apache web access.

2
  • not sure what I'm doing wrong, but this didn't work for me :( ubuntu@domU-12-31-39-16-26-01:/var/www$ sudo useradd ubuntu www-data Usage: useradd [options] LOGIN
    – SSH This
    Apr 11, 2013 at 18:52
  • @Alan: useradd and adduser are different commands and commonly confused. You can add your user to the group www-data with: sudo adduser $USER www-data As $USER is part of the env. vars - no need for replacement. Apr 16, 2013 at 15:15
4

don't use 777 just because it "works". You can use easier notation such as u+rwx in order to give the user the right permission. g for group, u for "user" and o for "others". chmod ugo+rwx is then equal to 777; anyone can do anything with any files or directory. Usually not what you want.

You may want to use setgid on the directory using chmod g+s. This way, when someone changes a file, the group ownership will stay the same. Also, when you create new files and directories, this will be inherited.

2
  • Thanks for the info, but if I'm the only one with ssh access to the box, can it still be a problem?
    – SSH This
    Apr 11, 2013 at 18:51
  • Yes, never neglect security. Give yourself the correct permissions, but not any other user. Remember; humans aren't the only users on your system. If one service gets compromised, it should not have the ability to compromise another. Apr 12, 2013 at 15:16
1

If you use an desktop environment, you can do this.
Open the terminal and enter:

gksudo nautilus

Enter your password and hit Enter. Navigate to the www folder and right-click. Choose properties and afterwards permission. Now you can change the access.
To quit Nautilus, just close it and to close the terminal, idem.

1
  • where we have nautilus in a VPS server?
    – Pavak Paul
    Apr 22, 2014 at 5:08
0

You could do this, if you just want to add your user:

sudo chgrp -R yourusername /var/www
sudo find /var/www -type d -exec chmod g=rwxs {} \;
sudo find /var/www -type f -exec chmod g=rws {} \; 

Replace yourusername with the actual user name that you want to add. One last thing, you can keep adding user names by repeating the command, only putting their user name.

Hope this helps!

Source

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .