我已经尝试解决这个问题几天了,但是没有成功,并且这个网站上的类似问题/答案也无法解决问题。
我在 GCE 上有 3 个不同的 VM 实例,其中两个上运行良好。
第三个情况是,我失去了通过控制台内置终端和直接通过 Mac 上的终端访问 SSH 的所有权限。
我创建了新的密钥对,并在单击 VM 实例上的编辑后将公钥添加到元和 ssh 密钥部分。
我一直收到“权限被拒绝(公钥)”错误。端口 22 正常,IP 已列入白名单,并且我已生成多个替换 SSH 密钥对来尝试修复此问题。但都不起作用。我无法通过 SSH 连接,并且我的 SFTP 客户端无法使用新密钥连接(尽管我使用其他实例进行 ssh 或 sftp 连接完全没有问题)。
.ssh 文件夹中有多个 ssh 密钥,但我认为这不是问题,因为其他密钥继续与不同的 VM 实例一起使用。似乎服务器上监视密钥的某些东西已损坏或缓存卡住并且需要刷新。如果是这种情况,任何知道哪个文件以及要做什么的帮助都会真正有帮助。此外,如果我无法使用 ssh 进入,我该如何编辑这些文件?
以下是-v 的结果:
Bobcomp:.ssh Bob$ sudo ssh -v [SERVER USER]@[SERVER IP]
OpenSSH_7.9p1, LibreSSL 2.7.3
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 48: Applying options for *
debug1: Connecting to [SERVER IP] [[SERVER IP]] port 22.
debug1: Connection established.
debug1: identity file /var/root/.ssh/id_rsa type -1
debug1: identity file /var/root/.ssh/id_rsa-cert type -1
debug1: identity file /var/root/.ssh/id_dsa type -1
debug1: identity file /var/root/.ssh/id_dsa-cert type -1
debug1: identity file /var/root/.ssh/id_ecdsa type -1
debug1: identity file /var/root/.ssh/id_ecdsa-cert type -1
debug1: identity file /var/root/.ssh/id_ed25519 type -1
debug1: identity file /var/root/.ssh/id_ed25519-cert type -1
debug1: identity file /var/root/.ssh/id_xmss type -1
debug1: identity file /var/root/.ssh/id_xmss-cert type -1
debug1: Local version string SSH-2.0-OpenSSH_7.9
debug1: Remote protocol version 2.0, remote software version OpenSSH_7.4p1 Debian-10+deb9u6
debug1: match: OpenSSH_7.4p1 Debian-10+deb9u6 pat OpenSSH_7.0*,OpenSSH_7.1*,OpenSSH_7.2*,OpenSSH_7.3*,OpenSSH_7.4*,OpenSSH_7.5*,OpenSSH_7.6*,OpenSSH_7.7* compat 0x04000002
debug1: Authenticating to [SERVER IP]:22 as '[SERVER USER]'
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: algorithm: curve25519-sha256
debug1: kex: host key algorithm: ecdsa-sha2-nistp256
debug1: kex: server->client cipher: [email protected] MAC: <implicit> compression: none
debug1: kex: client->server cipher: [email protected] MAC: <implicit> compression: none
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: Server host key: ecdsa-sha2-nistp256 SHA256:LOMx9T+sBw/LBUQvhsbaou5H4AwAMbUcnSWYzP0yKv0
debug1: Host '[SERVER IP]' is known and matches the ECDSA host key.
debug1: Found key in /var/root/.ssh/known_hosts:1
debug1: rekey after 134217728 blocks
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: rekey after 134217728 blocks
debug1: Will attempt key: /var/root/.ssh/id_rsa
debug1: Will attempt key: /var/root/.ssh/id_dsa
debug1: Will attempt key: /var/root/.ssh/id_ecdsa
debug1: Will attempt key: /var/root/.ssh/id_ed25519
debug1: Will attempt key: /var/root/.ssh/id_xmss
debug1: SSH2_MSG_EXT_INFO received
debug1: kex_input_ext_info: server-sig-algs=<ssh-ed25519,ssh-rsa,ssh-dss,ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521>
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey
debug1: Next authentication method: publickey
debug1: Trying private key: /var/root/.ssh/id_rsa
debug1: Trying private key: /var/root/.ssh/id_dsa
debug1: Trying private key: /var/root/.ssh/id_ecdsa
debug1: Trying private key: /var/root/.ssh/id_ed25519
debug1: Trying private key: /var/root/.ssh/id_xmss
debug1: No more authentication methods to try.
[SERVER USER]@[SERVER IP]: Permission denied (publickey).
任何帮助均感激不尽。
答案1
运行SSH命令时需要指定私钥的路径:
ssh -i [私钥路径] [用户名]@[外部IP地址]
以下是如何找到密钥[1]。
有关如何解决此类问题的更多信息,请参见[2]。
__
[1]https://cloud.google.com/compute/docs/instances/adding-removing-ssh-keys#locatesshkeys
[2]https://cloud.google.com/compute/docs/instances/connecting-advanced