关于在我的Ubuntu 14.4计算机上安装Git并遵循these如何获取和保存ssh密钥配对,我一直关注GitHub directions方向。
现在我尝试通过执行以下操作来提交远程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
编辑我试图通过打开文件夹并使用beckah
然后尝试向用户chown -R beckah .
授予读/写权限来查看错误是否在本地发生为chmod 777 -R testing/
的所有用户授予对该文件夹的读/写访问权限。当我尝试在之后提交项目时,它们都仍然呈现权限错误。
答案 0 :(得分:0)
虽然有人会从输出中想到这是一个远程权限问题,我认为它是本地的。从输出中可以看出,服务器上的SSH密钥注册正常。
可能本地的权限不正确,有些不适合您当前的用户帐户(只是一个猜测)。要解决此问题,请进入/git/testing
目录并发出以下命令:
sudo chown -R beckah .
这将确保beckah
用户对本地存储库中的所有文件(递归地)拥有所有权。
如果您是系统中唯一使用/git
目录的人,则上述情况应该没问题。如果/git
是您与Ubuntu系统上的其他用户共享的目录,那么您将不得不考虑创建一个新组并将其添加到其中。然后使用读写权限在整个/git
目录树中为该组授予组所有权。