Azure版Catalyst 9800-CLへのSSH公開鍵認証の接続試行が失敗して、下記のようにPasswordが要求されるケースがあったので関連する情報を整理しました。
sysadmin [ ~ ]$ ssh -i ~/.ssh/id_rsa azureuser@#.#.#.# (azureuser@#.#.#.#) Password: (azureuser@#.#.#.#) Password: (azureuser@#.#.#.#) Password: azureuser@#.#.#.#'s password: Connection closed by #.#.#.# port 22 sysadmin [ ~ ]$
環境情報
筆者はAzure Cloud Shellから ssh
コマンド (OpenSSH Client)を利用しています。
OpenSSH Clientのバージョンが 8.8 以上になっているのが注目点です。
sysadmin [ ~ ]$ ssh -V OpenSSH_8.8p1, OpenSSL 1.1.1k FIPS 25 Mar 2021 sysadmin [ ~ ]$
検証の際に手元のローカルPCの環境を汚さず、尚且つローカルPC環境への依存性を避けるために、Azure Cloud Shell環境上でできるだけ完結するような使い方をしたい背景がありました。
そのため、ssh
コマンドのバージョンはAzure Cloud Shell環境に大きく依存する使い方になっています。
事象の背景
OpenSSHのバージョン 8.8 ではSHA-1 ハッシュ アルゴリズムを用いたRSA署名がデフォルトで無効になっていたため ssh
コマンド使用時に Password:
プロンプトが表示されているようでした。
https://www.openssh.com/txt/release-8.8
This release disables RSA signatures using the SHA-1 hash algorithm by default.
また、SSH鍵としてはより強力な ED25519 や ECDS が推奨されておりましたが、AzureのVirtual Machineに対するSSH接続は、SSH Version 2でRSA且つ最小 2048 bitのサポート状況となっている現状がありました。(2023年08月時点)
Supported SSH key formats
Azure currently supports SSH protocol 2 (SSH-2) RSA public-private key pairs with a minimum length of 2048 bits. Other key formats such as ED25519 and ECDSA are not supported.
ソフトウェアの脆弱性対応などの観点からOpenSSH Clientの古いバージョンを引っ張り出して使うわけにもいかないため、Azureで唯一サポートされているRSAの種別のSSH鍵を用いながらOpenSSH Clientのバージョン 8.8 以上を利用すると、結果的にAzureのVirtual Machineに接続できなくなる状況に陥っておりました。
暫定的な対処策
セキュリティ レベルは下がりますが、OpenSSH Client側で暫定対処策として ssh-rsa
を -o
オプションを用いて有効化する方法があります。
ssh -o 'PubkeyAcceptedKeyTypes +ssh-rsa' azureuser@IP-ADDRESS
もしくは
ssh -o 'PubkeyAcceptedAlgorithms +ssh-rsa' azureuser@IP-ADDRESS
のコマンドになります。接続先情報 (azureuser@IP-ADDRESS
)の部分は適宜書き換えてください。
-o
のオプションで渡すキーワードに違いがあるのは、OpenSSHのバージョン 8.5 にて PubkeyAcceptedKeyTypes
が PubkeyAcceptedAlgorithms
にリネームされているためです。
https://www.openssh.com/txt/release-8.5
- ssh(1), sshd(8): rename the PubkeyAcceptedKeyTypes keyword to PubkeyAcceptedAlgorithms. The previous name incorrectly suggested that it control allowed key algorithms, when this option actually specifies the signature algorithms that are accepted. The previous name remains available as an alias. bz#3253
検証時のログ: SSH公開鍵認証の失敗 = Password要求時
筆者がOpenSSH ClientでSSH公開鍵認証で接続試行して失敗した際のログ情報を控えておきます。
sysadmin [ ~ ]$ ssh -V OpenSSH_8.8p1, OpenSSL 1.1.1k FIPS 25 Mar 2021 sysadmin [ ~ ]$ sysadmin [ ~ ]$ ssh -v azureuser@#.#.#.# OpenSSH_8.8p1, OpenSSL 1.1.1k FIPS 25 Mar 2021 debug1: Reading configuration data /etc/ssh/ssh_config debug1: Authenticator provider $SSH_SK_PROVIDER did not resolve; disabling debug1: Connecting to #.#.#.# [#.#.#.#] port 22. debug1: Connection established. debug1: identity file /home/sysadmin/.ssh/id_rsa type 0 debug1: identity file /home/sysadmin/.ssh/id_rsa-cert type -1 debug1: identity file /home/sysadmin/.ssh/id_dsa type -1 debug1: identity file /home/sysadmin/.ssh/id_dsa-cert type -1 debug1: identity file /home/sysadmin/.ssh/id_ecdsa type -1 debug1: identity file /home/sysadmin/.ssh/id_ecdsa-cert type -1 debug1: identity file /home/sysadmin/.ssh/id_ecdsa_sk type -1 debug1: identity file /home/sysadmin/.ssh/id_ecdsa_sk-cert type -1 debug1: identity file /home/sysadmin/.ssh/id_ed25519 type -1 debug1: identity file /home/sysadmin/.ssh/id_ed25519-cert type -1 debug1: identity file /home/sysadmin/.ssh/id_ed25519_sk type -1 debug1: identity file /home/sysadmin/.ssh/id_ed25519_sk-cert type -1 debug1: identity file /home/sysadmin/.ssh/id_xmss type -1 debug1: identity file /home/sysadmin/.ssh/id_xmss-cert type -1 debug1: Local version string SSH-2.0-OpenSSH_8.8 debug1: Remote protocol version 1.99, remote software version Cisco-1.25 debug1: compat_banner: match: Cisco-1.25 pat Cisco-1.* compat 0x60000000 debug1: Authenticating to #.#.#.#:22 as 'azureuser' debug1: load_hostkeys: fopen /home/sysadmin/.ssh/known_hosts2: No such file or directory debug1: load_hostkeys: fopen /etc/ssh/ssh_known_hosts: No such file or directory debug1: load_hostkeys: fopen /etc/ssh/ssh_known_hosts2: No such file or directory debug1: SSH2_MSG_KEXINIT sent debug1: SSH2_MSG_KEXINIT received debug1: kex: algorithm: ecdh-sha2-nistp256 debug1: kex: host key algorithm: rsa-sha2-512 debug1: kex: server->client cipher: aes256-ctr MAC: hmac-sha2-512 compression: none debug1: kex: client->server cipher: aes256-ctr MAC: hmac-sha2-512 compression: none debug1: expecting SSH2_MSG_KEX_ECDH_REPLY debug1: SSH2_MSG_KEX_ECDH_REPLY received debug1: Server host key: ssh-rsa SHA256:******************************************* debug1: load_hostkeys: fopen /home/sysadmin/.ssh/known_hosts2: No such file or directory debug1: load_hostkeys: fopen /etc/ssh/ssh_known_hosts: No such file or directory debug1: load_hostkeys: fopen /etc/ssh/ssh_known_hosts2: No such file or directory debug1: Host '#.#.#.#' is known and matches the RSA host key. debug1: Found key in /home/sysadmin/.ssh/known_hosts:1 debug1: rekey out after 4294967296 blocks debug1: SSH2_MSG_NEWKEYS sent debug1: expecting SSH2_MSG_NEWKEYS debug1: SSH2_MSG_NEWKEYS received debug1: rekey in after 4294967296 blocks debug1: Will attempt key: /home/sysadmin/.ssh/id_rsa RSA SHA256:******************************************* debug1: Will attempt key: /home/sysadmin/.ssh/id_dsa debug1: Will attempt key: /home/sysadmin/.ssh/id_ecdsa debug1: Will attempt key: /home/sysadmin/.ssh/id_ecdsa_sk debug1: Will attempt key: /home/sysadmin/.ssh/id_ed25519 debug1: Will attempt key: /home/sysadmin/.ssh/id_ed25519_sk debug1: Will attempt key: /home/sysadmin/.ssh/id_xmss debug1: SSH2_MSG_SERVICE_ACCEPT received debug1: Authentications that can continue: publickey,keyboard-interactive,password debug1: Next authentication method: publickey debug1: Offering public key: /home/sysadmin/.ssh/id_rsa RSA SHA256:******************************************* debug1: send_pubkey_test: no mutual signature algorithm debug1: Trying private key: /home/sysadmin/.ssh/id_dsa debug1: Trying private key: /home/sysadmin/.ssh/id_ecdsa debug1: Trying private key: /home/sysadmin/.ssh/id_ecdsa_sk debug1: Trying private key: /home/sysadmin/.ssh/id_ed25519 debug1: Trying private key: /home/sysadmin/.ssh/id_ed25519_sk debug1: Trying private key: /home/sysadmin/.ssh/id_xmss debug1: Next authentication method: keyboard-interactive (azureuser@#.#.#.#) Password: debug1: Authentications that can continue: publickey,keyboard-interactive,password (azureuser@#.#.#.#) Password: debug1: Authentications that can continue: publickey,keyboard-interactive,password (azureuser@#.#.#.#) Password: sysadmin [ ~ ]$
特記すべきは、共通の署名アルゴリズムが見つからなかった旨のログが出てる点です。
debug1: send_pubkey_test: no mutual signature algorithm
その後、keyboard-interactive
による認証に遷移して Password:
のプロンプトが表示されています。
debug1: Next authentication method: keyboard-interactive (azureuser@#.#.#.#) Password:
備忘録
他の解決方法までは見つけられず手詰まりだったので、現状の暫定的な対処策と検証時の情報を一先ず整理しておきました。 そのため、本記事を参考する際はAzure, OpenSSH, Catalyst 9800などの最新状況も合わせてチェックするようにしてください。