ssh 在 CentOS 8 (GCE VM) 上停止運作

ssh 在 CentOS 8 (GCE VM) 上停止運作

ssh 在 CentOS 8 (GCE VM) 上停止運作

我讓 ssh 使用 pub/私鑰對在 GCE CentOS 8 虛擬機器上正常工作了兩天,然後就停止工作了。

現在我得到:

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 狀態 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 已打開,我可以使用配置相同網路的方式連接到虛擬機器。

當我在瀏覽器中開啟一個視窗時,我可以透過 ssh 連線: https://console.cloud.google.com/compute/instancesDetail/zones/us-west1-b/instances/<instance>?project=<project-name>

我關閉了selinux: setenforce 0

在`/etc/selinux/config中,我設定SELINUX=停用 並重新啟動虛擬機,但沒有這樣的運氣。

相關內容