Google Cloud-权限被拒绝(公钥)

Google Cloud-权限被拒绝(公钥)

我有一个正在运行的 GCP 实例debian-8-jessie-v20170619(已弃用)。重启后,我失去了对机器的 ssh 访问权限(无法通过 Web、终端或 gcloud cli 进行 ssh)。现在我的 Wordpress 博客的 MySQL 数据库出现问题,我需要 ssh。有几十个问题同名,所以我阅读了大部分问题并尝试:

  1. 重新生成 ssh 密钥,添加到元数据(在实例和项目中)
  2. 关闭 OS Login 并尝试 ssh。打开 OS Login 并尝试 ssh。
  3. 串行控制台方法(启动脚本未创建用户;因此登录失败)
  4. 使用 ssh -i key user@host 而不是 gcloud cli
  5. 添加密钥至authorized_keys

这些都不起作用。以下是$ gcloud compute ssh MyVM --ssh-flag="-vvv"

OpenSSH_8.1p1, LibreSSL 2.7.3
debug1: Reading configuration data /Users/Jash/.ssh/config
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 47: Applying options for *
debug2: resolve_canonicalize: hostname 35.237.214.57 is address
debug2: ssh_connect_direct
debug1: Connecting to 35.237.214.57 [35.237.214.57] port 22.
debug1: Connection established.
debug1: identity file /Users/Jash/.ssh/google_compute_engine type 0
debug1: identity file /Users/Jash/.ssh/google_compute_engine-cert type -1
debug1: Local version string SSH-2.0-OpenSSH_8.1
debug1: Remote protocol version 2.0, remote software version OpenSSH_6.7p1 Debian-5+deb8u8
debug1: match: OpenSSH_6.7p1 Debian-5+deb8u8 pat OpenSSH* compat 0x04000000
debug2: fd 3 setting O_NONBLOCK
debug1: Authenticating to 35.237.214.57:22 as 'Jash'
debug1: using hostkeyalias: compute.2217424771252360577
debug3: hostkeys_foreach: reading file "/Users/Jash/.ssh/google_compute_known_hosts"
debug3: record_hostkey: found key type ECDSA in file /Users/Jash/.ssh/google_compute_known_hosts:1
debug3: load_hostkeys: loaded 1 keys from compute.2217424771252360577
debug3: order_hostkeyalgs: prefer hostkeyalgs: [email protected],[email protected],[email protected],ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521
debug3: send packet: type 20
debug1: SSH2_MSG_KEXINIT sent
debug3: receive packet: type 20
debug1: SSH2_MSG_KEXINIT received
debug2: local client KEXINIT proposal
debug2: KEX algorithms: curve25519-sha256,[email protected],ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,diffie-hellman-group-exchange-sha256,diffie-hellman-group16-sha512,diffie-hellman-group18-sha512,diffie-hellman-group14-sha256,diffie-hellman-group14-sha1,ext-info-c
debug2: host key algorithms: [email protected],[email protected],[email protected],ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521,[email protected],[email protected],[email protected],[email protected],ssh-ed25519,rsa-sha2-512,rsa-sha2-256,ssh-rsa
debug2: ciphers ctos: [email protected],aes128-ctr,aes192-ctr,aes256-ctr,[email protected],[email protected]
debug2: ciphers stoc: [email protected],aes128-ctr,aes192-ctr,aes256-ctr,[email protected],[email protected]
debug2: MACs ctos: [email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],hmac-sha2-256,hmac-sha2-512,hmac-sha1
debug2: MACs stoc: [email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],hmac-sha2-256,hmac-sha2-512,hmac-sha1
debug2: compression ctos: none,[email protected],zlib
debug2: compression stoc: none,[email protected],zlib
debug2: languages ctos:
debug2: languages stoc:
debug2: first_kex_follows 0
debug2: reserved 0
debug2: peer server KEXINIT proposal
debug2: KEX algorithms: [email protected],ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,diffie-hellman-group-exchange-sha256,diffie-hellman-group14-sha1
debug2: host key algorithms: ssh-rsa,ssh-dss,ecdsa-sha2-nistp256,ssh-ed25519
debug2: ciphers ctos: aes128-ctr,aes192-ctr,aes256-ctr,[email protected],[email protected],[email protected]
debug2: ciphers stoc: aes128-ctr,aes192-ctr,aes256-ctr,[email protected],[email protected],[email protected]
debug2: MACs ctos: [email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],hmac-sha2-256,hmac-sha2-512,hmac-sha1
debug2: MACs stoc: [email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],hmac-sha2-256,hmac-sha2-512,hmac-sha1
debug2: compression ctos: none,[email protected]
debug2: compression stoc: none,[email protected]
debug2: languages ctos:
debug2: languages stoc:
debug2: first_kex_follows 0
debug2: reserved 0
debug1: kex: algorithm: [email protected]
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
debug3: send packet: type 30
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug3: receive packet: type 31
debug1: Server host key: ecdsa-sha2-nistp256 SHA256:/8U8cYg6EIhbKq5aDfb9DySyrP6JEli2B3iUpLKx6lE
debug1: using hostkeyalias: compute.2217424771252360577
debug3: hostkeys_foreach: reading file "/Users/Jash/.ssh/google_compute_known_hosts"
debug3: record_hostkey: found key type ECDSA in file /Users/Jash/.ssh/google_compute_known_hosts:1
debug3: load_hostkeys: loaded 1 keys from compute.2217424771252360577
debug1: Host 'compute.2217424771252360577' is known and matches the ECDSA host key.
debug1: Found key in /Users/Jash/.ssh/google_compute_known_hosts:1
debug3: send packet: type 21
debug2: set_newkeys: mode 1
debug1: rekey out after 134217728 blocks
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug3: receive packet: type 21
debug1: SSH2_MSG_NEWKEYS received
debug2: set_newkeys: mode 0
debug1: rekey in after 134217728 blocks
debug1: Will attempt key: /Users/Jash/.ssh/google_compute_engine RSA SHA256:dHe8jHKOHpUXq/rriZMV3ya/HgaJeyrLqGLTe2+OJnc explicit
debug2: pubkey_prepare: done
debug3: send packet: type 5
debug3: receive packet: type 6
debug2: service_accept: ssh-userauth
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug3: send packet: type 50
debug3: receive packet: type 51
debug1: Authentications that can continue: publickey
debug3: start over, passed a different list publickey
debug3: preferred publickey,keyboard-interactive,password
debug3: authmethod_lookup publickey
debug3: remaining preferred: keyboard-interactive,password
debug3: authmethod_is_enabled publickey
debug1: Next authentication method: publickey
debug1: Offering public key: /Users/Jash/.ssh/google_compute_engine RSA SHA256:dHe8jHKOHpUXq/rriZMV3ya/HgaJeyrLqGLTe2+OJnc explicit
debug3: send packet: type 50
debug2: we sent a publickey packet, wait for reply
debug3: receive packet: type 51
debug1: Authentications that can continue: publickey
debug2: we did not send a packet, disable method
debug1: No more authentication methods to try.
[email protected]: Permission denied (publickey).
ERROR: (gcloud.compute.ssh) [/usr/bin/ssh] exited with return code [255].

答案1

不幸的是,您没有提供串行端口日志。我在下面提供了典型的 SSH 故障排除步骤。请随时更新您的问题以获取更具体的指导。

检查串行端口日志Compute Engine-> VM instances-> 单击 NAME_OF_YOUR_VM -> 在VM instance details查找部分日志并点击Serial port 1 (console)。最好重启 VM 实例以获取完整信息。

如果发现与磁盘空间相关的错误/警告您可以尝试根据文档调整其大小调整区域永久性磁盘的大小或关注这篇文章恢复无法访问的实例或完整的启动磁盘

再次尝试通过串行控制台排除虚拟机实例故障(这个启动脚本我使用过很多次并且有效):

  1. 启用串行控制台连接Compute Engine-> VM instances-> 点击NAME_OF_YOUR_VM_INSTANCE-> 点击EDIT-> 转至部分Remote access并检查Enable connecting to serial ports

  2. 创建临时用户和密码登录:关闭你的虚拟机并设置一个启动脚本通过添加在部分Custom metadatastartup-script和值:

     #!/bin/bash
     useradd --groups google_sudoers tempuser
     echo "tempuser:password" | chpasswd
    

    然后启动您的虚拟机。

  3. 通过串行端口连接到您的虚拟机Compute Engine-> VM instances-> 点击NAME_OF_YOUR_VM_INSTANCE-> 然后点击Connect to serial console

    如果再次连接失败,您可以再次检查串行端口日志以查看有关启动脚本执行的详细信息。

  4. 检查哪里出了问题。

  5. 禁用通过串行端口访问Compute Engine-> VM instances-> 点击NAME_OF_YOUR_VM_INSTANCE-> 点击EDIT-> 转至部分Remote access并取消选中Enable connecting to serial ports。更多详细信息请参阅文档与串行控制台交互

如果你无法通过串行控制台连接,尝试按照文档操作SSH 故障排除部分检查虚拟机实例而不关闭它在另一台虚拟机上检查虚拟机的磁盘您也可以用同样的方式将数据传输到另一个正在运行的 VM 实例

相关内容