Github推送错误。权限被拒绝。

7
我正在尝试使用以下命令从Ubuntu 11.10创建我的第一个repo:
sudo git push -u origin master 但是我遇到了以下错误:
Permission denied (publickey). fatal: The remote end hung up unexpectedly
如何解决这个问题?
我也尝试了以下命令:git push -u origin master。但是我收到了以下错误信息:
error: could not lock config file .git/config: Permission denied error: could not lock config file .git/config: Permission denied Branch master set up to track remote branch master from origin. error: unable to create directory for .git/refs/remotes/origin/master error: Cannot lock the ref 'refs/remotes/origin/master'. Everything up-to-date
5个回答

6

6

是的,这可能是真正的原因。 :) - Kjuly

2

你好,可能是因为您尝试使用root身份进行git push,使用sudo命令,您是否设置了公钥或root密钥?通常情况下,只需提供您的密钥而不是root密钥即可,这可能是您遇到此类错误的原因。


1
如果您认为这是由于虚假锁定引起的,请尝试删除锁定文件: Mac 或 *nix
rm -v .git/config.lock

Windows

del .git/config.lock

1
我猜你可能正在使用类似etckeeper这样的工具来保留/etc更改的版本控制历史记录 - 这似乎需要你使用sudo(至少这是有道理的)。
我和你有同样的问题 - 我需要使用sudo,但无法使用在github注册的密钥进行操作(注意到这个密钥和我作为常规sudo用户使用的相同)。
你需要的是-E标志 - 没有其他更改需要(假设你已经设置了ssh而不是https)。
➜ sudo -E git push -u origin master
Enumerating objects: 8, done.
Counting objects: 100% (8/8), done.
Delta compression using up to 16 threads
Compressing objects: 100% (6/6), done.
Writing objects: 100% (6/6), 661 bytes | 661.00 KiB/s, done.
Total 6 (delta 4), reused 0 (delta 0), pack-reused 0
remote: Resolving deltas: 100% (4/4), completed with 2 local objects.
To github.com:[redacted].git
   5fedc61..3a9b7f6  master -> master
Branch 'master' set up to track remote branch 'master' from 'origin'.
(base) 

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接