git拉过ssh会给出更奇怪的错误

这是我的设置。

  1. 我的git仓库在bitbucket中
  2. 我已经在我的远程aws ec2服务器上创build了密钥,并将其保存在~/.ssh文件夹中
  3. 然后我通过远程服务器上的ssh-agent添encryption钥
  4. 在bitbucket网站上更新这些密钥。

当我login到我的远程服务器,并运行git pull我的git存储库一切工作正常。 这里没有问题。

但是当我通过Windows上的cygwin bash运行相同的时候,它给了我这个错误:

 Permission denied (publickey). fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists. 

我在我的Windows机器上执行以下操作

 ssh -i xyz.pem user@ip -t 'sudo sh deploy.sh' 

deploy.shcd放到我的仓库里,然后做一个git pull

为什么会发生这个问题? 我也应该保持这些SSH密钥在我的Windows机器上? 任何帮助将是非常宝贵的。

通过使用sudo运行sh ,您正在有效地使用root的.ssh凭据访问回购。 这些与您生成的并添加到bitbucket的密钥不匹配。

我想知道你为什么需要sudo ,是否只能由root用户写回? 一个select是将root的ssh密钥添加到bitbucket,或者避免使用sudo