【问题标题】:Unable to Commit to Github: Permission denied无法提交到 Github:权限被拒绝
【发布时间】:2014-10-29 16:08:41
【问题描述】:

在将 Git 安装到我的 Ubuntu 14.4 机器上时,我一直遵循 these 的指导,并遵循 GitHub directions 的有关如何获取和保存 ssh 密钥配对的指导。

现在我正在尝试通过执行以下操作来提交到远程 Github 位置:

beckah@the-tank:/git/testing$ git push origin master
Counting objects: 3, done.
Writing objects: 100% (3/3), 208 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To git@github.com:rsheeler/Ubuntu_Test.git
 * [new branch]      master -> master
error: unable to create directory for .git/refs/remotes/origin/master
error: Cannot lock the ref 'refs/remotes/origin/master'.

它似乎无法访问我的 GitHub 位置。为了验证,我执行了与仅提到sudo git push origin master 相同的命令,并得到以下错误Permission denied (publickey)

为了提供更多背景知识,我通过以下方式创建了我的 ssh 密钥:

beckah@the-tank:/git/testing$ ssh-keygen -t rsa -C "rebeccasheeler@gmail.com"
Generating public/private rsa key pair.
Enter file in which to save the key (/home/account/.ssh/id_rsa): 
Enter passphrase (empty for no passphrase): 
Enter same passphrase again:  
Your identification has been saved in /home/account/.ssh/id_rsa.
Your public key has been saved in /home/account/.ssh/id_rsa.pub.
The key fingerprint is:
##:##:##:##:##:##:##:##:##:##:##:##:##:##:##:## rebeccasheeler@gmail.com
The key's randomart image is:
{little image here}
beckah@the-tank:/git/testing$ eval "$(ssh-agent -s)"
Agent pid 30342
beckah@the-tank:/git/testing$ ssh-add ~/.ssh/id_rsa
Enter passphrase for /home/beckah/.ssh/id_rsa: 
Identity added: /home/beckah/.ssh/id_rsa (/home/beckah/.ssh/id_rsa)
beckah@the-tank:/git/testing$ sudo apt-get install xclip
[sudo] password for beckah: 
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following NEW packages will be installed:
  xclip
0 upgraded, 1 newly installed, 0 to remove and 4 not upgraded.
Need to get 16.5 kB of archives.
After this operation, 67.6 kB of additional disk space will be used.
Get:1 http://us.archive.ubuntu.com/ubuntu/ trusty/universe xclip i386 0.12+svn84-4 [16.5 kB]
Fetched 16.5 kB in 0s (113 kB/s) 
Selecting previously unselected package xclip.
(Reading database ... 194616 files and directories currently installed.)
Preparing to unpack .../xclip_0.12+svn84-4_i386.deb ...
Unpacking xclip (0.12+svn84-4) ...
Processing triggers for man-db (2.6.7.1-1) ...
Setting up xclip (0.12+svn84-4) ...
beckah@the-tank:/git/testing$ xclip -sel clip < ~/.ssh/id_rsa.pub
beckah@the-tank:/git/testing$ ssh -T git@github.com
Warning: Permanently added the RSA host key for IP address '192.30.252.128' to the list of known hosts.
Hi rsheeler! You've successfully authenticated, but GitHub does not provide shell access.
beckah@the-tank:/git/testing$ sudo git push origin master
Warning: Permanently added the RSA host key for IP address '192.30.252.129' to the list of known hosts.
Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.
beckah@the-tank:/git/testing$ git remote add origin git@github.com:rsheeler/Ubuntu_Test.git
fatal: remote origin already exists.
beckah@the-tank:/git/testing$ git push origin master
Counting objects: 3, done.
Writing objects: 100% (3/3), 208 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To git@github.com:rsheeler/Ubuntu_Test.git
 * [new branch]      master -> master
error: unable to create directory for .git/refs/remotes/origin/master
error: Cannot lock the ref 'refs/remotes/origin/master'.

当我使用 xcut 复制 ssh 密钥时可以看到,我将密钥粘贴到了我在 GitHub 上帐户的 SSH 密钥 部分。

我也试过在论坛上看以下问题

https://askubuntu.com/questions/137165/git-ssh-permission-denied-publickey

https://askubuntu.com/questions/267392/using-authorized-keys-with-git


编辑:我试图通过打开文件夹并使用chown -R beckah . 向用户beckah 授予读/写权限然后尝试授予读/写权限来查看错误是否在本地发生具有chmod 777 -R testing/ 的所有用户对该文件夹的写入权限。之后我尝试提交该项目时,它们仍然出现权限错误。

【问题讨论】:

  • 进入你的本地源目录,我猜是/git/hosting。然后在该目录中发出命令sudo chown -R beckah . 从输出中显示您的帐户是beckah。然后再次尝试您的 git push。我认为这是一个本地权限问题(不是远程问题)

标签: linux git github ssh permissions


【解决方案1】:

虽然人们会从输出中认为这是一个远程权限问题,但我认为它是本地的。从输出中可以看出,您在服务器上的 SSH 密钥已正确注册。

可能本地权限不正确,有些权限不适用于您当前的用户帐户(只是猜测)。要解决这个问题,请进入您的 /git/testing 目录并发出以下命令:

sudo chown -R beckah .

这将确保beckah 用户对本地存储库中的所有文件(递归)拥有所有权。

如果您是系统上唯一使用/git 目录的人,上述内容应该没问题。如果/git 是您在 Ubuntu 系统上与其他用户共享的目录,那么您将不得不考虑创建一个新组并将自己添加到其中。然后在整个 /git 目录树中为该组授予组所有权,并具有读写权限。

【讨论】:

  • 这似乎不起作用。 :/ 我从文件夹中执行了以下命令:sudo chown -R beckah . 然后当我尝试执行 sudo git push origin master 时收到错误消息 Permission denied (publickey). fatal: Could not read from remote repository. 然后我尝试使用 chmod 授予所有帐户对测试文件夹的读写权限命令或chmod 777 -R testing/,但仍然得到权限错误:L
  • 好的,下一个问题。 rsheeler是你在github设置的实际账号吗?
  • 是的。那是实际的帐户。
  • git remote -v的输出是什么
猜你喜欢
  • 2013-12-09
  • 2018-05-08
  • 2012-01-18
  • 2012-04-25
  • 2020-01-08
  • 2011-12-24
  • 2018-04-25
  • 2016-02-29
相关资源
最近更新 更多