将 ssh 连接到 google 虚拟实例总是被拒绝权限(公钥)

connect ssh to google virtual instanse always got Permission denied (publickey)

我运行cat ~/.ssh/id_rsa.pub 并将 ssh-rsa AAAA...hwFbh me@me.local 复制到 google 云上的 SSH 密钥 VM 实例中,然后保存 然后我尝试在我的终端上登录:

ssh my-project@ip-address

然后得到 Permission denied (publickey)

我认为我将 ssh 密钥放入我的 VM 实例的正确方法,我从未成功使用我的 ssh 到 google 云,但在 AWS 和 digital ocean 上总是没有问题为此,

如果我使用 glcoud

gcloud compute ssh --zone "us-central1-f" "my-project" --project "my-project-277520"

已成功登录到我的 VM 实例

为什么我要用命令登录 ssh my-project@ip-address 因为如果我无法使用此命令访问,我的 git 服务器会出错,它会抛出相同的东西 Permission denied (publickey)

fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

我无法为该 VM 实例上的 git 挂钩执行此操作 git push production master 我正在该服务器上使用 git 挂钩

如何解决这件事伙计们?我现在真的为此困了好几天:(,当然我一直在查看 Whosebug 并用谷歌搜索来解决这个问题,但我终于需要在这里为你寻求帮助

copy ssh-rsa AAAA...hwFbh me@me.local into SSH Keys VM instance on google cloud and then save

这取决于您复制的准确程度(自 you cannot directly add it to the remote ~/.ssh/authorized_keys

例如:“Adding or removing project-wide public SSH keys

确保它被复制为一个连续行。

然后检查您的本地权限(密钥为 600)