无法连接到 SSH GCE

无法连接到 SSH GCE

我在 Google Compute Engine 上创建了一个虚拟机。之前我连接 SSH 时没有遇到任何问题,但当我尝试将文件上传到 FTP 时,它导致会话崩溃,然后我根本无法登录 FTP,也无法通过浏览器登录 SSH。当我通过浏览器运行 SSH 时,它会无休止地加载。我尝试在互联网上查找我的问题并尝试了所有方法,但都无济于事。如何解决这个问题?请帮忙。

调试信息:

OpenSSH_7.9p1 Debian-10+deb10u2, OpenSSL 1.1.1g  21 Apr 2020

debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: Applying options for *
debug2: resolve_canonicalize: hostname 34.107.7.177 is address
debug2: ssh_connect_direct
debug1: Connecting to 34.107.7.177 [34.107.7.177] port 22.
debug1: Connection established.
debug1: identity file /home/menadzer_odzidzi/.ssh/id_rsa type -1
debug1: identity file /home/menadzer_odzidzi/.ssh/id_rsa-cert type -1
debug1: identity file /home/menadzer_odzidzi/.ssh/id_dsa type -1
debug1: identity file /home/menadzer_odzidzi/.ssh/id_dsa-cert type -1
debug1: identity file /home/menadzer_odzidzi/.ssh/id_ecdsa type -1
debug1: identity file /home/menadzer_odzidzi/.ssh/id_ecdsa-cert type -1
debug1: identity file /home/menadzer_odzidzi/.ssh/id_ed25519 type -1
debug1: identity file /home/menadzer_odzidzi/.ssh/id_ed25519-cert type -1
debug1: identity file /home/menadzer_odzidzi/.ssh/id_xmss type -1
debug1: identity file /home/menadzer_odzidzi/.ssh/id_xmss-cert type -1
debug1: Local version string SSH-2.0-OpenSSH_7.9p1 Debian-10+deb10u2
debug1: Remote protocol version 2.0, remote software version OpenSSH_7.9p1 Debian-10+deb10u2
debug1: match: OpenSSH_7.9p1 Debian-10+deb10u2 pat OpenSSH* compat 0x04000000
debug2: fd 3 setting O_NONBLOCK
debug1: Authenticating to 34.107.7.177:22 as 'root'
debug3: hostkeys_foreach: reading file "/home/menadzer_odzidzi/.ssh/known_hosts"
debug3: record_hostkey: found key type ECDSA in file /home/menadzer_odzidzi/.ssh/known_hosts:1
debug3: load_hostkeys: loaded 1 keys from 34.107.7.177
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: 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
debug2: host key algorithms: rsa-sha2-512,rsa-sha2-256,ssh-rsa,ecdsa-sha2-nistp256,ssh-ed25519
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]
debug2: compression stoc: none,[email protected]
debug2: languages ctos:
debug2: languages stoc:
debug2: first_kex_follows 0
debug2: reserved 0
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
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:MsUrlwvWs5j4zxPD8B2c/8ry3EeeX/xZ9fcRkhjlb/A
debug3: hostkeys_foreach: reading file "/home/menadzer_odzidzi/.ssh/known_hosts"
debug3: record_hostkey: found key type ECDSA in file /home/menadzer_odzidzi/.ssh/known_hosts:1
debug3: load_hostkeys: loaded 1 keys from 34.107.7.177
debug1: Host '34.107.7.177' is known and matches the ECDSA host key.
debug1: Found key in /home/menadzer_odzidzi/.ssh/known_hosts:1
debug3: send packet: type 21
debug2: set_newkeys: mode 1
debug1: rekey 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 after 134217728 blocks
debug1: Will attempt key: /home/menadzer_odzidzi/.ssh/id_rsa
debug1: Will attempt key: /home/menadzer_odzidzi/.ssh/id_dsa
debug1: Will attempt key: /home/menadzer_odzidzi/.ssh/id_ecdsa
debug1: Will attempt key: /home/menadzer_odzidzi/.ssh/id_ed25519
debug1: Will attempt key: /home/menadzer_odzidzi/.ssh/id_xmss
debug2: pubkey_prepare: done
debug3: send packet: type 5
debug3: receive packet: type 7
debug1: SSH2_MSG_EXT_INFO received
debug1: kex_input_ext_info: server-sig-algs=<ssh-ed25519,ssh-rsa,rsa-sha2-256,rsa-sha2-512,ssh-dss,ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521>
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 gssapi-keyex,gssapi-with-mic,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: Trying private key: /home/menadzer_odzidzi/.ssh/id_rsa
debug3: no such identity: /home/menadzer_odzidzi/.ssh/id_rsa: No such file or directory
debug1: Trying private key: /home/menadzer_odzidzi/.ssh/id_dsa
debug3: no such identity: /home/menadzer_odzidzi/.ssh/id_dsa: No such file or directory
debug1: Trying private key: /home/menadzer_odzidzi/.ssh/id_ecdsa
debug3: no such identity: /home/menadzer_odzidzi/.ssh/id_ecdsa: No such file or directory
debug1: Trying private key: /home/menadzer_odzidzi/.ssh/id_ed25519
debug3: no such identity: /home/menadzer_odzidzi/.ssh/id_ed25519: No such file or directory
debug1: Trying private key: /home/menadzer_odzidzi/.ssh/id_xmss
debug3: no such identity: /home/menadzer_odzidzi/.ssh/id_xmss: No such file or directory
debug2: we did not send a packet, disable method
debug1: No more authentication methods to try.
[email protected]: Permission denied (publickey).

答案1

首先,你应该收集日志

  1. 转到Compute Engine-> VM instances-> 单击 NAME_OF_YOUR_VM -> 在VM instance details查找部分日志并点击Serial port 1 (console)
  2. 再次重新启动您的 VM 实例。
  3. 检查完整启动日志中是否存在任何错误或/和警告。

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

如果实例的磁盘空间完全用完,或者没有运行 Linux 客户环境,则无法自动调整根文件系统的大小,即使您增加了支持它的持久磁盘的大小也是如此。如果您无法连接到实例,或者启动磁盘已满且无法调整其大小,则必须创建新实例并从快照重新创建启动磁盘以调整其大小。

否则尝试通过串行控制台排除虚拟机实例故障

  1. 启用串行控制台连接使用gcloud命令:

     gcloud compute instances add-metadata NAME_OF_YOUR_VM_INSTANCE \
     --metadata serial-port-enable=TRUE
    

或前往Compute Engine-> VM instances-> 点击NAME_OF_YOUR_VM_INSTANCE-> 点击EDIT-> 前往部分Remote access并检查Enable connecting to serial ports

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

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

然后启动您的虚拟机。

  1. 通过串行端口连接到您的虚拟机使用gcloud命令:

     gcloud compute connect-to-serial-port NAME_OF_YOUR_VM_INSTANCE
    

    或前往Compute Engine-> VM instances-> 点击NAME_OF_YOUR_VM_INSTANCE-> 然后点击Connect to serial console

  2. 检查哪里出了问题。

  3. 禁用通过串行端口访问使用gcloud命令:

     gcloud compute instances add-metadata NAME_OF_YOUR_VM_INSTANCE \
     --metadata serial-port-enable=FALSE
    

或前往Compute Engine-> VM instances-> 点击NAME_OF_YOUR_VM_INSTANCE-> 点击EDIT-> 前往部分Remote access并取消选中Enable connecting to serial ports。请记住,根据文档与串行控制台交互

警告:交互式串行控制台不支持基于 IP 的访问限制,例如 IP 白名单。如果您在实例上启用交互式串行控制台,客户端可以尝试从任何 IP 地址连接到该实例。如果知道正确的 SSH 密钥、用户名、项目 ID、区域和实例名称,任何人都可以连接到该实例。使用防火墙规则来控制对您的网络和特定端口的访问。

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

相关内容