Wapiti
Wapiti

Reputation: 1911

Pushing to personal git repo over ssh: permission denied

I have a raspberry pi with a USB key with 512 gigs hooked up to my local network. I use it as my personal, private git repo, because I finally outgrew bitbucket. It works great, except...

I ssh in with the username pi, but my git repo has files and directories all owned by git. I've observed that from time to time I cannot push. I'll get an error like this:

error: unable to write sha1 filename ./objects/77/33acda0f90974cb73ad8b02fcd83896b3eeb94: Permission denied To 192.168.0.2:/srv/git/writing.git ! [remote rejected] master -> master (unable to migrate objects to permanent storage) error: failed to push some refs to '[email protected]:/srv/git/writing.git'

I've found that I can circumvent this with the horrible hack of changing permissions to 777, so clearly the issue is that the ssh user pi and the directory user git are different. New git directories (such as dir 77 in the error above) are generated dynamically by git with permissions 755, which is why I cannot write to them.

Is there a way to change the group and owner of dynamically created git directories? If I create a git user and use that to ssh onto the pi, will that work? What is the right way of dealing with this?

Upvotes: 1

Views: 372

Answers (1)

tobias
tobias

Reputation: 1004

Git's official documentation recommends that you create a user called git and setup restrictions so that "the git user can only use the SSH connection to push and pull Git repositories and can’t shell onto the machine".

You can find the documentation here: https://git-scm.com/book/en/v2/Git-on-the-Server-Setting-Up-the-Server

Upvotes: 2

Related Questions