How to sudo git clone and safely change permission to another user
sudo chown -R user:user path
This recursively changes the owner and group of everything under path
to user
.
Related videos on Youtube
Piotr Kula
Updated on September 18, 2022Comments
-
Piotr Kula over 1 year
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: -
-
muru almost 9 yearsWhy not give
Pi
write permissions to the directory you want to clone in? -
Piotr Kula almost 9 yearsI 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
andchown
work together but everywhere I read is not to screw it up because of security.. -
muru almost 9 yearsOK, for a start, post the current permissions and ownership of the directory you do
git clone
in. Say it is/foo/bar
, then dostat /foo/bar
. And add the groups ofPi
:groups Pi
. Edit your post to add more information. -
muru almost 9 yearsYou'll probably want to use a solution like in this question: askubuntu.com/questions/46331/…, and the information requested will tell you how to modify the steps there.
-
muru almost 9 yearsAh, no, I meant the ownership of
/home/test
in this case - the directory containing the git repo, not the git repo itself. -
Piotr Kula almost 9 yearsI have to use
sudo mkdir
to create directories too. so its stillroot
. Actually I have to do almost everything withsudo
-
muru almost 9 yearsIs
test
an actual user? Or is that just a representative path? -
Piotr Kula almost 9 yearsthat was just me creating a direcoty quickly, was meant to be home/pi i did a stat of the original user /home/pi dir
-
muru almost 9 yearsIf you're working in
/home/pi
, you don't needsudo
at all. Where are you working in? -
Piotr Kula almost 9 yearsI 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? -
muru almost 9 yearsThat depends on what you're doing. Are you following the steps here: github.com/aspnet/Home/blob/dev/GettingStartedDeb.md?
-
Piotr Kula almost 9 yearsYea 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 almost 9 yearsThanks 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.
-
-
rkeatin3 almost 9 yearsSpecify the username you want to change ownership to before specifying the directory:
sudo chown -R pi /home/pi/Home
-
Piotr Kula almost 9 yearsOh yes, offcourse, I missed that. OK I did that... and.............. it worked. :)
-
Piotr Kula almost 9 yearsI did a stat on the direcotry and now its
UID: pi and GID root
but the home direcoty isUID: pi and GID: pi
what are the implications of this? -
rkeatin3 almost 9 yearsNot sure. I'm a bit new to Linux myself.
-
Piotr Kula almost 9 yearsWell, I suppose this is much better than doing a
chmod 0777
on the entire directory. Thanks! -
Olathe almost 9 yearsYou'll want to do
sudo chown -R user:user path
to change the group as well.