Permission Denied when using absolute path, relative path works OK
Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Permission Denied when using absolute path, relative path works OK
OK - full disclosure, not really a newbie to Linux but this is my first post on LinuxQuestions, and it feels like my problem could maybe be a rookie mistake, so I will post here:
I am trying to write to a file as a particular user (www-data) using "su". The file being written to is owned by www-data:www-data, and has write permissions. Writing to the file as this user fails if I use an absolute pathname, but it works if I use a relative pathname.
Here are the details:
The directory where the file lives:
root@moe:/home/pete/cm# ls -l |grep logs
drwxrwxr-x 2 www-data www-data 4096 Jul 31 11:38 logs
The contents of that directory:
root@moe:/home/pete/cm# ls -l logs
total 5564
-rw-rw-r-- 1 www-data www-data 0 Jul 31 11:40 hm.log
-rw-rw-r-- 1 www-data www-data 199915 Jul 2 2013 hm.log.1
-rw-rw-r-- 1 www-data www-data 199886 Jun 30 2013 hm.log.2
-rw-rw-r-- 1 www-data www-data 199850 Jun 29 2013 hm.log.3
-rw-rw-r-- 1 www-data www-data 199875 Jun 26 2013 hm.log.4
-rw-rw-r-- 1 www-data www-data 199913 Jun 23 2013 hm.log.5
-rw-rw-r-- 1 www-data www-data 23204 Jul 31 11:37 server.log
Now I try to make a change to a file like so:
root@moe:/home/pete/cm# cd logs
root@moe:/home/pete/cm/logs# su www-data -c "touch hm.log"
and it works. However, when I do:
root@moe:/home/pete/cm/logs# su www-data -c "touch /home/pete/cm/logs/hm.log"
touch: cannot touch ‘/home/pete/cm/logs/hm.log’: Permission denied
I need to use absolute paths for this. I cannot figure out why it works using relative paths but not absolute paths. /home is mounted to a different device than /, could that be the problem?
I tried to make the relative path longer to isolate the point at which it no longer works, and found the following:
- in directory /home/pete/cm/logs, changing hm.log works
- in directory /home/pete/cm, changing logs/hm.log works
- in directory /home/pete, changing cm/logs/hm/log fails.
... and what is ownership/permission of /home/pete?
You have files with owner and group both different from the home directory owner. Is pete a member of www-data group? is www-data a member of pete group?
Hi - thanks for your reply. Here are the answers to your questions:
Permissions on /home/pete:
drwx------ 110 pete pete 12288 Jul 31 06:36 pete
is pete a member of www-data group? No:
uid=1000(pete) gid=1000(pete) groups=1000(pete),4(adm),24(cdrom),27(sudo),30(dip),46(plugdev),108(lpadmin),124(sambashare)
Is www-data a member of pete group? No:
uid=33(www-data) gid=33(www-data) groups=33(www-data)
Hi - thanks for your reply. Here are the answers to your questions:
Permissions on /home/pete:
drwx------ 110 pete pete 12288 Jul 31 06:36 pete
is pete a member of www-data group? No:
uid=1000(pete) gid=1000(pete) groups=1000(pete),4(adm),24(cdrom),27(sudo),30(dip),46(plugdev),108(lpadmin),124(sambashare)
Is www-data a member of pete group? No:
uid=33(www-data) gid=33(www-data) groups=33(www-data)
Then you shouldn't have a directory that's owned by www-data in pete's home directory. You'll always face permission hell trying to operate that way. Pete's home directory is for pete, and nobody else. Similarly, www-data's home directory is for www-data, and nobody else. If you need a neutral location that both users can share, then create one elsewhere, like "/home/cm" or something, and give it the necessary permissions.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.