6

On Raspberry Pi, I log in as the default user Pi.

I do a sudo git clone on a repository, because it needs to create directories.

This is specific for DNU/DNX, because we cannot run sudo dnu restore yet, or ever? I don't know. It gets permission denied on the packages file causing it to error and I cant run the sample.

pi@raspberrypi ~/Home/samples/1.0.0-beta4/HelloMvc $ dnu restore
Restoring packages for /home/pi/Home/samples/1.0.0-beta4/HelloMvc/project.json
Writing lock file /home/pi/Home/samples/1.0.0-beta4/HelloMvc/project.lock.json
----------
System.UnauthorizedAccessException: Access to the path "/home/pi/Home/samples/1.0.0-beta4/HelloMvc/project.lock.json" is denied.

I had to do a chmod -R 0777 /Samples but that obviously is not the correct way to fix this.

How can I safely or easily use sudo git clone but then make everything as if Pi user did the clone, or allow the Pi user to work properly.

I did try chmod Pi:Pi on the specific packages file but that didn't help. I didn't try it recursively but I don't really know how to do this properly.

So I did a fresh clone as requested in comments, let see whats going on.

pi@raspberrypi /home/test $ sudo git clone https://github.com/aspnet/Home.git

pi@raspberrypi /home/test $ stat /home/test/Home
  File: `/home/test/Home'
  Size: 4096            Blocks: 8          IO Block: 4096   directory
Device: b302h/45826d    Inode: 153225      Links: 4
Access: (0755/drwxr-xr-x)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2015-06-23 20:42:42.819728005 +0000
Modify: 2015-06-23 20:42:48.649688508 +0000
Change: 2015-06-23 20:42:48.649688508 +0000
 Birth: -

pi@raspberrypi /home/test $ stat /home/test
  File: `/home/test'
  Size: 4096            Blocks: 8          IO Block: 4096   directory
Device: b302h/45826d    Inode: 153224      Links: 3
Access: (0755/drwxr-xr-x)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2015-06-23 20:42:31.099806322 +0000
Modify: 2015-06-23 20:42:42.819728005 +0000
Change: 2015-06-23 20:42:42.819728005 +0000
 Birth: -

pi@raspberrypi /home/test $ stat /home/pi
  File: `/home/pi'
  Size: 4096            Blocks: 8          IO Block: 4096   directory
Device: b302h/45826d    Inode: 29          Links: 7
Access: (0755/drwxr-xr-x)  Uid: ( 1000/      pi)   Gid: ( 1000/      pi)
Access: 2015-02-16 15:09:21.453774622 +0000
Modify: 2015-06-23 19:33:46.613016792 +0000
Change: 2015-06-23 19:33:46.613016792 +0000
 Birth: -
Piotr Kula
  • 632
  • 2
  • 6
  • 14
  • Why not give Pi write permissions to the directory you want to clone in? – muru Jun 23 '15 at 20:37
  • I don't know..? I don't know how to do any of this to be honest. I am happy I figured out what the problem was and found a work around.. but how do I do this properly? I am only going to be using Pi user. I have very little understanding of how chmod and chown work together but everywhere I read is not to screw it up because of security.. – Piotr Kula Jun 23 '15 at 20:39
  • 1
    OK, for a start, post the current permissions and ownership of the directory you do git clone in. Say it is /foo/bar, then do stat /foo/bar. And add the groups of Pi: groups Pi. [Edit] your post to add more information. – muru Jun 23 '15 at 20:41
  • You'll probably want to use a solution like in this question: http://askubuntu.com/questions/46331/how-to-avoid-using-sudo-when-working-in-var-www, and the information requested will tell you how to modify the steps there. – muru Jun 23 '15 at 20:42
  • Ah, no, I meant the ownership of /home/test in this case - the directory containing the git repo, not the git repo itself. – muru Jun 23 '15 at 20:46
  • I have to use sudo mkdir to create directories too. so its still root. Actually I have to do almost everything with sudo – Piotr Kula Jun 23 '15 at 20:48
  • Is test an actual user? Or is that just a representative path? – muru Jun 23 '15 at 20:49
  • that was just me creating a direcoty quickly, was meant to be home/pi i did a stat of the original user /home/pi dir – Piotr Kula Jun 23 '15 at 20:49
  • If you're working in /home/pi, you don't need sudo at all. Where are you working in? – muru Jun 23 '15 at 20:52
  • I am actually cloning the original files in /var/usr/source then running the sample there so I can proxy to it using nginx. I am not actually cloning anything in to the pi directory. Will it be easier if I actually clone into the /home/pi directory instead? Will the permissions then cascade across everything there? – Piotr Kula Jun 23 '15 at 20:54
  • That depends on what you're doing. Are you following the steps here: https://github.com/aspnet/Home/blob/dev/GettingStartedDeb.md? – muru Jun 23 '15 at 20:58
  • Yea those step are way before and all done. I am actually cloning the /Home repo. I just did a sudo clone into /var/pi, it created a Home directory, I went in there to the sample I want and did a dnu restore, I am getting the same problem. accees to lock.json file denied. Even though the sample in under /home/pi - This problem never used to exist (like last month) but you know, its beta, then changing things, fixing things, making more secure etc. Besides those help files are way out of date. It tooke me ages to work out how to do that properly from other sources – Piotr Kula Jun 23 '15 at 21:00
  • Thanks for trying to help muru - Linux permissions is black magic to me. Just trying to at least do it as correct as possible and try to learn what all this means. Thanks again. – Piotr Kula Jun 23 '15 at 21:14

1 Answers1

11
sudo chown -R user:user path

This recursively changes the owner and group of everything under path to user.

Olathe
  • 4,240
rkeatin3
  • 126
  • 1
  • 3