I have set up a git repository on my server. Created a new user 'git'. My repos are located in /srv/git/example.git
. I was able to git remote add origin git@domain/srv/git/example.git
then I added and committed my changes.
我在我的服务器上设置了一个git存储库。创建了一个新用户'git'。我的回购位于/srv/git/example.git。我能够git远程添加源git@domain/srv/git/example.git然后我添加并提交了我的更改。
However when I tried git push origin master
it failed on:
但是,当我尝试git push origin master时,它失败了:
fatal: unable to create temporary file: permission denied' and 'fatal: sha1 file write error: invalid argument'
致命:无法创建临时文件:权限被拒绝'和'致命:sha1文件写入错误:无效参数'
On the server I ran:
在我运行的服务器上:
sudo chown -R git:git /srv/git/`
This fixed my problem but I am wondering if this was the correct thing to do?
这解决了我的问题,但我想知道这是否是正确的做法?
2 个解决方案
#1
19
On the server I ran sudo chown -R git:git /srv/git/ - this fixed my problem but I am wondering if this was the correct thing to do?
在服务器上我运行sudo chown -R git:git / srv / git / - 这解决了我的问题,但我想知道这是否是正确的做法?
Absolutely. The problem previously was that the git user, who you're logging in as via SSH, could not write to the repository.
绝对。之前的问题是,您通过SSH登录的git用户无法写入存储库。
Depending on your needs, you may consider different combinations of users and SSH keys, or one of the many additional programs (gitolite etc) that can be used to more finely control access.
根据您的需要,您可以考虑用户和SSH密钥的不同组合,或者可以用于更精细地控制访问的许多其他程序(gitolite等)之一。
#2
8
First, fix file permissions in your remote .git
dir e.g.
首先,修复远程.git目录中的文件权限,例如
sudo chmod -R ug+w /var/www/.git
sudo chown -R git:git /var/www/.git
or root:root
if you want to assign members of root
group for push access.
或root:root如果要为根组分配成员以进行推送访问。
Then git repository on the destination host needs to be set as shared, so the following command on remote needs to be run:
然后需要将目标主机上的git存储库设置为共享,因此需要运行以下远程命令:
git config core.sharedRepository group
#1
19
On the server I ran sudo chown -R git:git /srv/git/ - this fixed my problem but I am wondering if this was the correct thing to do?
在服务器上我运行sudo chown -R git:git / srv / git / - 这解决了我的问题,但我想知道这是否是正确的做法?
Absolutely. The problem previously was that the git user, who you're logging in as via SSH, could not write to the repository.
绝对。之前的问题是,您通过SSH登录的git用户无法写入存储库。
Depending on your needs, you may consider different combinations of users and SSH keys, or one of the many additional programs (gitolite etc) that can be used to more finely control access.
根据您的需要,您可以考虑用户和SSH密钥的不同组合,或者可以用于更精细地控制访问的许多其他程序(gitolite等)之一。
#2
8
First, fix file permissions in your remote .git
dir e.g.
首先,修复远程.git目录中的文件权限,例如
sudo chmod -R ug+w /var/www/.git
sudo chown -R git:git /var/www/.git
or root:root
if you want to assign members of root
group for push access.
或root:root如果要为根组分配成员以进行推送访问。
Then git repository on the destination host needs to be set as shared, so the following command on remote needs to be run:
然后需要将目标主机上的git存储库设置为共享,因此需要运行以下远程命令:
git config core.sharedRepository group