linux - 无法提交到Github : Permission denied

标签 linux git github ssh permissions

我一直在关注these在我的 Ubuntu 14.4 机器上安装 Git 时的说明并遵循 GitHub directions关于如何获取和保存 ssh key 配对。

现在我正在尝试通过执行以下操作来提交到远程 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 相同的命令,并收到以下错误权限被拒绝(publickey)

为了提供更多背景信息,我通过以下方式创建了 ssh key :

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 key 时所看到的,我将 key 粘贴到了我在 GitHub 上的帐户的 SSH key 部分。

我还尝试在论坛上查看以下问题

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 -Rtesting/为所有用户授予对该文件夹的读/写访问权限。当我之后尝试提交到该项目时,它们仍然出现权限错误。

最佳答案

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

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

sudo chown -R beckah .

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

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

关于linux - 无法提交到Github : Permission denied,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25673434/

相关文章:

git - 我更新了来自上游/master 的 pull 请求的分支。如果我再次将分支推送到github,会污染 pull 请求吗?

git - merge pull 请求时,提交出现在本地不存在的 GitHub 上

从另一个程序控制 C 守护进程

linux - 运行此命令时出现错误 mahout trainnb -i path_to/train-vectors -el -li path_to/labelindex -o path_to/model -ow -c

GitHub 包含来自另一个存储库

git - 如何在 Git 存储库中找到具有多个父级的所有提交?

git - 在 Visual Studio 中更改跟踪的 Git 分支

linux - 如何在我的 AWS EC2 实例上安装特定字体?

linux - 具有 1 个主存储库的多个 git 存储库

GitHub 高级搜索默认行为