LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This 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


Reply
  Search this Thread
Old 07-31-2015, 03:11 PM   #1
eleventyfour
LQ Newbie
 
Registered: Jul 2015
Posts: 4

Rep: Reputation: Disabled
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.

I'm stumped. Any ideas?
 
Old 07-31-2015, 03:40 PM   #2
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=14, FreeBSD_10{.0|.1|.2}
Posts: 3,876
Blog Entries: 1

Rep: Reputation: 1997Reputation: 1997Reputation: 1997Reputation: 1997Reputation: 1997Reputation: 1997Reputation: 1997Reputation: 1997Reputation: 1997Reputation: 1997Reputation: 1997
... 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?

Full info needed please.
 
Old 07-31-2015, 04:06 PM   #3
eleventyfour
LQ Newbie
 
Registered: Jul 2015
Posts: 4

Original Poster
Rep: Reputation: Disabled
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)
 
Old 07-31-2015, 04:15 PM   #4
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,258

Rep: Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947
Quote:
Originally Posted by eleventyfour View Post
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.
 
Old 07-31-2015, 04:26 PM   #5
eleventyfour
LQ Newbie
 
Registered: Jul 2015
Posts: 4

Original Poster
Rep: Reputation: Disabled
Interesting that it works one way but not another - I guess that's a good definition of permission hell!

I moved the cm directory to a neutral location and everything works.

Thanks for your help!
 
Old 07-31-2015, 04:32 PM   #6
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=14, FreeBSD_10{.0|.1|.2}
Posts: 3,876
Blog Entries: 1

Rep: Reputation: 1997Reputation: 1997Reputation: 1997Reputation: 1997Reputation: 1997Reputation: 1997Reputation: 1997Reputation: 1997Reputation: 1997Reputation: 1997Reputation: 1997
Quote:
Originally Posted by eleventyfour View Post
Interesting that it works one way but not another - I guess that's a good definition of permission hell!

I moved the cm directory to a neutral location and everything works.

Thanks for your help!
When you are in that directory before you su, using relative paths, the process does not have to traverse any forbidden directories to get there.

When you use absolute paths as www-data it cannot traverse /home/pete so it fails.

Yep, permission hell, it is designed that way! Better to work with it than against it.

Glad you got it figured out!
 
Old 07-31-2015, 04:56 PM   #7
eleventyfour
LQ Newbie
 
Registered: Jul 2015
Posts: 4

Original Poster
Rep: Reputation: Disabled
Thanks for the explanation, it makes perfect sense. Appreciate the help!
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] tar absolute and relative path mmhs Linux - Newbie 13 08-09-2012 09:09 PM
How to change Absolute path to Relative path sahil.jammu Linux - Newbie 2 05-31-2011 05:57 AM
java applet not loading image with relative path but loads image with absolute path amolgupta Programming 2 07-20-2009 02:58 PM
relative to absolute path vishalbutte Programming 4 01-14-2006 04:17 PM


All times are GMT -5. The time now is 12:55 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration