权限被拒绝(公钥)

时间:2018-04-29 07:15:51

标签: ssh google-cloud-platform

我正在运行Google云端实例。我能够通过ssh成功连接到实例。

但是我无法将端口转发到我的localhost。

这是我使用的命令:

ssh -L 16006:127.0.0.1:8080 username@instance_external_ip

当我运行上面的命令时,我收到以下错误

The authenticity of the host cannot be determined. username@instance_external_ip : Permission Denied (public key)

如何解决这个问题?

1 个答案:

答案 0 :(得分:2)

我找到了这个问题的答案。我遇到的问题是服务器不知道ssh密钥。所以,我做了以下工作并且有效。

我删除了本地计算机中的所有ssh密钥,并使用以下命令连接到我的gcloud实例。 gcloud命令自动创建ssh密钥,并自动传输到云ssh密钥。因此,无需手动复制粘贴密钥。

gcloud compute --project "project_name" ssh --zone "zone_name" "instance_name"

在此之后我使用ssh连接到我的实例。在尝试ssh隧道之前,由于服务器不会知道localhost,它会在运行ssh -L ....时拒绝权限。

因此,不要直接通过ssh -L ...连接,而是连接ssh-key目录中存储的.ssh文件。使用以下命令。

ssh -i ~/.ssh/google_compute-engine -L <ur localhost port number>:127.0.0.1:<remote_host_port> username@server_ip