The use of chmod
is for changing permissions, the command chown
is for changing ownership of files & directories.
ownership
To change a directory's ownership you can use the following command:
$ sudo chown -R me /srv/www/htdocs
NOTE: we're using the sudo
facility to elevate our privileges to the same level as root for these commands, without having to become root.
permissions
To change the permissions on this directory:
$ sudo chmod -R 777 /srv/www/htdocs
umask
Using the command umask
sets up your terminal so that when files & directories are created their permissions can be influenced a bit. Caution should be used when using umask
since there are situations where it won't give you permissions exactly the way you think.
For a directory it seems fine:
$ for i in `seq 1 7`;do echo "umask: 00$i"; umask 00$i; rm -fr blah; mkdir blah;ls -l|grep blah;done
umask: 001
drwxrwxrw- 2 saml saml 4096 Jul 29 14:39 blah
umask: 002
drwxrwxr-x 2 saml saml 4096 Jul 29 14:39 blah
umask: 003
drwxrwxr-- 2 saml saml 4096 Jul 29 14:39 blah
umask: 004
drwxrwx-wx 2 saml saml 4096 Jul 29 14:39 blah
umask: 005
drwxrwx-w- 2 saml saml 4096 Jul 29 14:39 blah
umask: 006
drwxrwx--x 2 saml saml 4096 Jul 29 14:39 blah
umask: 007
drwxrwx--- 2 saml saml 4096 Jul 29 14:39 blah
However it won't let you have files exactly the way you might intend them to be with particular umasks. See umask 006
for example below:
$ for i in `seq 1 7`;do echo "umask: 00$i"; umask 00$i; rm -fr blah; touch blah;ls -l|grep blah;done
umask: 001
-rw-rw-rw- 1 saml saml 0 Jul 29 14:40 blah
umask: 002
-rw-rw-r-- 1 saml saml 0 Jul 29 14:40 blah
umask: 003
-rw-rw-r-- 1 saml saml 0 Jul 29 14:40 blah
umask: 004
-rw-rw--w- 1 saml saml 0 Jul 29 14:40 blah
umask: 005
-rw-rw--w- 1 saml saml 0 Jul 29 14:40 blah
umask: 006
-rw-rw---- 1 saml saml 0 Jul 29 14:40 blah
umask: 007
-rw-rw---- 1 saml saml 0 Jul 29 14:40 blah
There are others, this is just to highlight an example!
So what should you do?
Given you're dealing with a Apache directory (based on the path /srv/www/htdocs
) I'd look for a Unix group that your user me
and the user that Apache is running as are both members of. You can use the groups
command to determine this:
$ groups saml
saml : saml vboxusers jupiter newgrp
$ groups apache
apache : apache
You can also use the id
command:
$ id saml
uid=500(saml) gid=501(saml) groups=501(saml),502(vboxusers),503(jupiter),10000(newgrp)
$ id apache
uid=48(apache) gid=48(apache) groups=48(apache)
On my system Apache is run by a user apache
. Looking at this user you can see that it's in a single group apache
as well. So one approach would be to add the user me
to this group.
For example, add me
to the apache
groups:
$ sudo usermod -a -G apache me
The other approach would be to create another group and add both apache
and me
to this secondary group (for example, apacheplus), and then run this command on /srv/www/htdocs
:
$ sudo chgrp -R apacheplus /srv/www/htdocs
sh
compatible shells there is aumask
shell builtin.chmod
expects file mode as parameter. The command to which you can pass a user name ischown
. Or was that only a typo in your post?umask
, I recommend you ACLs.