我在Windows上使用TortoiseGit。当我试图从标准Windows资源管理器的上下文菜单克隆时,我得到这个错误:

请确保您拥有正确的访问权限并且存储库存在

更准确地说,终端的快照如下:

——progress -v "git@arobotdev:\git\AlfaRobot. exe。git”“C: \ \ AlfaRobot” 克隆到“C:\Work\AlfaRobot”… 权限被拒绝,请重试。 权限被拒绝,请重试。 权限被拒绝(公钥,密码)。 无法从远程存储库读取。 请确保您拥有正确的访问权限 并且存储库存在。 Git没有干净地退出(退出代码128)(21450 ms @ 19.09.2014 10:36:58)

我应该怎么做才能使git正常工作?


当前回答

我在用Ubuntu

在阅读了许多答案后,没有一个能解决问题,即使我已经添加了SSH密钥到我的git帐户,并尝试使用SSH -T git@gitlab.com测试它,它说欢迎<我的用户名>,但它仍然告诉我,我没有访问权限。后来我找到了原因:

通常情况下,如果你不是root用户,它会要求你对每个git命令都运行sudo。

当运行sudo git clone <SSH....>(例如)。它将在root权限下执行,但无意中创建SSH密钥时,我以普通用户运行它,并将密钥保存在~/中。Ssh /id_rsa,解析绝对路径为“/home/username/. Ssh /id_rsa”。当做sudo git克隆…它在/root/.ssh/id_rsa中查找SSH密钥

为什么我可以确定。查看git在哪里查找SSH密钥。执行命令sudo GIT_TRACE=1 GIT_SSH_COMMAND="ssh -vvv" git clone <您的仓库在ssh >。它将显示在哪里查找SSH密钥。

所以我建议的解决方案是:

重新创建您的SSH密钥(遵循此说明),但在第一步运行sudo su,然后应该就可以了。

其他回答

类似的问题:

我给密码时,git克隆使用SSH URL的git。 所以这个错误现在显示,每次我打开VS Code在Windows 10

下面修复了这个问题:

1。在CMD下执行以下命令

setx SSH_ASKPASS "C:\Program Files\Git\mingw64\libexec\git-core\git-gui--askpass"
setx DISPLAY needs-to-be-defined

2。退出CMD & VS Code

3.重新打开VS Code

4所示。VS Code现在显示一个弹出对话框,我们可以输入passspharse

以上命令适用于Windows操作系统,类似的指令也适用于Linux/MAC。

进入你的cmd并运行:git config——global http。sslverify假

您正在尝试通过ssh: git@arobotdev..克隆存储库。,并且您的SSH密钥在服务器上没有正确设置。原因有很多:

您的公钥可能没有保存在用户git的authorized_keys文件中 如果1不为真,则“您的私钥不保存在您的HOMEDIR的。ssh/文件夹中”。 权限设置不正确

如果以上三点都不属实,那么我唯一的结论就是: git@arobotdev: AlfaRobot.git 假设AlfaRobot。git在git用户的HOMEDIR目录下,而不是在git用户的HOMEDIR目录下的名为git的文件夹中。

将这些行添加到你的.get/config文件中(感谢@kovshenin回答Git Pull: Change Authentication):

[credential]
    helper = wincred

The first thing you may want to confirm is the internet connection. Though, internet issues mostly will say that the repo cannot be accessed. Ensure you have set up ssh both locally and on your github. See how Ensure you are using the ssh git remote. If you had cloned the https, just set the url to the ssh url, with this git command git remote set-url origin git@github.com:your-username/your-repo-name.git If you have set up ssh properly but it just stopped working, do the following: eval "$(ssh-agent -s)" ssh-add If you are still having the issue, check to ensure that you have not deleted the ssh from your github. In a case where the ssh has been deleted from github, you can add it back. Use pbcopy < ~/.ssh/id_rsa.pub to copy the ssh key and then go to your github ssh setting and add it.

我建议你总是使用ssh。对于我合作过的大多数团队来说,除非使用ssh,否则您无法访问回购(大多数是私有的)。对于初学者来说,这可能看起来很难,但后来你会发现它更容易和更安全。