ssh 在 CentOS 8(GCE VM)上停止工作
我在 GCE CentOS 8 VM 上让 ssh 正常工作,并且发布/私钥对工作正常,持续了两天,然后它就停止工作了。
现在我得到:
Permission denied (publickey,gssapi-keyex,gssapi-with-mic).
所以它本来可以正常工作,这意味着一切都已设置、配置正确,所有权限都正常工作,但现在它却无法正常工作,所以这不是配置问题。配置没有任何变化。
我在 CentOS 7 上运行了相同的设置,它一直运行,从未出现故障、停止工作或出现问题。
配置正确,我检查了文件和目录的权限。
$cd $HOME/.ssh
$ls -al .
结果:
drwx------. 3 user group 156 Oct 17 10:11 .
drwxrwx---. 12 user group 4096 Oct 17 10:09 ..
-rw-------. 1 user group 197 Oct 17 10:09 authorized_keys
我生成了一个像这样的密钥(在 cygwin 中),并将 .pub 内容放在 GCE VM 上的 /home/user/.ssh/authorized_keys 中
ssh-keygen -f id_ed25519 -o -a 100 -t ed25519 -C "from:cygwin"
以前它还在工作,但现在却不工作了。
我的连接脚本:
#!/bin/bash
IP=x.x.x.x
LOCAL_KEYFILE="/c/home/user/.ssh/id_ed25519"
REMOTE_USER='user'
ssh -v -i $LOCAL_KEYFILE $REMOTE_USER@$IP
$systemctl status sshd.service
● sshd.service - OpenSSH server daemon
Loaded: loaded (/usr/lib/systemd/system/sshd.service; enabled; vendor preset: enabled)
Active: active (running) since Thu 2019-10-17 10:19:12 UTC; 17ms ago
Docs: man:sshd(8)
man:sshd_config(5)
Main PID: 2504 (sshd)
Tasks: 1 (limit: 26213)
Memory: 1.1M
CGroup: /system.slice/sshd.service
└─2504 /usr/sbin/sshd -D [email protected],[email protected],aes256-ctr,aes256-cbc,[email protected],aes128-ctr,aes128-cbc [email protected],[email protected],[email protected]>
Oct 17 10:19:12 host_name systemd[1]: Starting OpenSSH server daemon...
Oct 17 10:19:12 host_name sshd[2504]: Server listening on 0.0.0.0 port 22.
Oct 17 10:19:12 host_name sshd[2504]: Server listening on :: port 22.
Oct 17 10:19:12 host_name systemd[1]: Started OpenSSH server daemon.
尝试连接时的详细输出:
OpenSSH_8.0p1, OpenSSL 1.1.1d 10 Sep 2019
debug1: Connecting to x.x.x.x [x.x.x.x] port 22.
debug1: Connection established.
debug1: identity file /g/home/user/.ssh/id_ed25519 type 3
debug1: identity file /g/home/user/.ssh/id_ed25519-cert type -1 <== I dunno what this is, I don't have this file local
debug1: Local version string SSH-2.0-OpenSSH_8.0
debug1: Remote protocol version 2.0, remote software version OpenSSH_7.8
debug1: match: OpenSSH_7.8 pat OpenSSH* compat 0x04000000
debug1: Authenticating to 34.82.235.87:22 as 'proc'
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
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
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: Server host key: ecdsa-sha2-nistp256 SHA256:nfWd1FFBjYKQ7G7j4hkftEfB8UowSKkwfJzC2T8UF1g
debug1: Host '34.82.235.87' is known and matches the ECDSA host key.
debug1: Found key in /home/<another-unrelated-user>/.ssh/known_hosts:11 <== why is it reference another user here?
debug1: rekey out after 134217728 blocks
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: rekey in after 134217728 blocks
debug1: Will attempt key: /g/home/user/.ssh/id_ed25519 ED25519 SHA256:7o0XJjVnZLuzi+fO1NUUkFKpwKqw87u208IBy53zHcI explicit
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,null>
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mic
debug1: Next authentication method: publickey
debug1: Offering public key: /g/home/user/.ssh/id_ed25519 ED25519 SHA256:7o0XJjVnZLuzi+fO1NUUkFKpwKqw87u208IBy53zHcI explicit
debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mic
debug1: No more authentication methods to try.
[email protected]: Permission denied (publickey,gssapi-keyex,gssapi-with-mic).
我发现一些文章说我应该运行这些命令,所以我这样做了:
restorecon -Rv /home/user/.ssh/
restorecon -Rv /home/user/.ssh/authorized_keys
semanage fcontext -a -t ssh_home_t "/home/user/.ssh/authorized_keys"
然后在运行完每一个之后,我重新启动了 sshd,并尝试连接,并得到了相同的结果(相同的错误消息)。重新启动命令:
systemctl restart sshd.service
任何想法都将不胜感激,这令人困惑。
GCE 防火墙设置没有任何变化,端口 22 已打开,我可以使用配置了相同网络的 VM 进行连接。
我可以通过 ssh 连接,在浏览器中打开一个窗口:
https://console.cloud.google.com/compute/instancesDetail/zones/us-west1-b/instances/<instance>?project=<project-name>
我使用以下命令关闭了 selinux:
setenforce 0
在 /etc/selinux/config 中,我设置SELINUX=已禁用 并重新启动了虚拟机,但仍然没有成功。