1

I'm using OpenSuSE and my computer has only 2 accounts: root and me.I have a directory /srv/www/htdocs/abc.

I just want to set it up so that when new folders or files are created in this directory they will have the permissions set to 777.

When new files are created in this directory, I have to set them to 777 again to gain write access.

I use root and type:

chmod me /srv/www/htdocs

But I doesn't work. How can I do that?

5
  • Which shell? In sh compatible shells there is a umask shell builtin.
    – manatwork
    Commented Jul 29, 2013 at 11:28
  • chmod expects file mode as parameter. The command to which you can pass a user name is chown. Or was that only a typo in your post?
    – manatwork
    Commented Jul 29, 2013 at 11:34
  • Thank for all replies. I use "umask" command and it work thank manatwork so much umask 000 /srv/www/htdocs Have a nice day.
    – tunghk_54
    Commented Jul 29, 2013 at 17:40
  • 1
    If you need different default permissions or do not want to change your umask, I recommend you ACLs.
    – jofel
    Commented Jul 29, 2013 at 18:52
  • HI @jofel, thank for your suggestion, I will try that.
    – tunghk_54
    Commented Jul 29, 2013 at 19:06

1 Answer 1

1

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
1
  • @tunghk_54 - Glad it was helpful. If your issue's resolved please mark this as the accepted answer so that others know it's been resolved.
    – slm
    Commented Jul 29, 2013 at 19:03

You must log in to answer this question.

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