linux:openssh:client

ssh クライアントの使い方

単純に接続

$ ssh user_name@server_name.com

ポートを指定して接続

$ ssh user_name@server_name.com -p22022

接続先へポートフォワード
ローカルの8080ポートへの要求をリモートのlocalhost:80に転送

$ ssh user_name@server_name.com -L10080:localhost:80


ローカルの1022ポートへの要求をリモートの192.168.1.1:22に転送

$ ssh user_name@server_name.com -L1022:192.168.1.1:22
  • Linux or Mac では ssh-keygen を使用して、公開/秘密キーのペアを生成する。
    (-C オプションでコメントを付加しておくとよい)
    -t オプションには暗号タイプを指定する。
    -b オプションには暗号強度の bit 数を指定する。

    ED25519 の場合

    $ ssh-keygen -t ed25519 -f ~/.ssh/id_ed25519_tomoyan -C "Tomoyan Ed25519"

    Generating public/private ed25519 key pair.
    Enter passphrase (empty for no passphrase): <- パスフレーズを入力
    Enter same passphrase again: <- 確認用のパスフレーズを入力
    Your identification has been saved in /home/tomoyan/.ssh/id_ed25519_tomoyan
    Your public key has been saved in /home/tomoyan/.ssh/id_ed25519_tomoyan.pub
    The key fingerprint is:
    SHA256:D0T9myN6IEIMOTmISmgcQQYoV5zhllcABOdcE8F6NpQ Tomoyan Ed25519
    The key's randomart image is:
    +--[ED25519 256]--+
    |O*+B*=*=o.       |
    |B+B=ooE+  .      |
    |=. =*o. .  .     |
    |.  .+.+.    .    |
    |   . o .S    o   |
    |    . . .o. +    |
    |     . . o.. .   |
    |        . .      |
    |         .       |
    +----[SHA256]-----+
    

    ECDSA の場合

    $ ssh-keygen -t ecdsa -b 521 -f ~/.ssh/id_ecdsa_tomoyan -C "Tomoyan ECDSA"

    Generating public/private ecdsa key pair.
    Enter passphrase (empty for no passphrase): <- パスフレーズを入力
    Enter same passphrase again: <- 確認用のパスフレーズを入力
    Your identification has been saved in /home/tomoyan/.ssh/id_ecdsa_tomoyan
    Your public key has been saved in /home/tomoyan/.ssh/id_ecdsa_tomoyan.pub
    The key fingerprint is:
    SHA256:7WXQjZN0GI16XUbBW5OX1frL84xiPIC0BiU0WiPPZow Tomoyan ECDSA
    The key's randomart image is:
    +---[ECDSA 521]---+
    |    ..=     o=ooO|
    |     O.o.  oo=.=*|
    |    E *o  ..=..+=|
    |     o. ......o. |
    |       oSo..o  . |
    |        +..o    .|
    |       .  .o  . .|
    |            =  * |
    |           . o. =|
    +----[SHA256]-----+
    

    RSA の場合

    $ ssh-keygen -t rsa -b 2048 -f ~/.ssh/id_rsa_tomoyan -C "tomoyan rsa"

    Generating public/private rsa key pair.
    Enter passphrase (empty for no passphrase): <- パスフレーズを入力
    Enter same passphrase again: <- 確認用のパスフレーズを入力
    Your identification has been saved in /home/tomoyan/.ssh/id_rsa_tomoyan
    Your public key has been saved in /home/tomoyan/.ssh/id_rsa_tomoyan.pub
    The key fingerprint is:
    SHA256:j+beqQE6RJSI2k5rvQfHZXzqhFuxPPpZiNUvQcu4+H4 tomoyan rsa
    The key's randomart image is:
    +---[RSA 2048]----+
    | . ...           |
    |. ...            |
    |..  .  .  .      |
    |. o.    ==..     |
    | o o...=S==      |
    |  +.o.+=B= o     |
    | .  o+o**.+ .    |
    |    ..++.=Eo     |
    |     . +Ooo      |
    +----[SHA256]-----+
    

    秘密キーはパーミッション: 600(rw- --- ---)で ~/.ssh/id_rsa_tomoyan に生成される。
    公開キーはパーミッション: 644(rw- r-- r--)で ~/.ssh/id_rsa_tomoyan.pub に生成される。

    他からコピーしてきた場合など、クライアント側の秘密キーのパーミッションが適切に設定されていない場合は、警告が表示されて接続できないことがある。(以下は Mac OS X の警告の例)

    @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
    @         WARNING: UNPROTECTED PRIVATE KEY FILE!          @
    @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
    Permissions 0777 for '/Users/tomoyan/.ssh/id_rsa_tomoyan' are too open.
    It is recommended that your private key files are NOT accessible by others.
    This private key will be ignored.
    bad permissions: ignore key: /Users/tomoyan/.ssh/id_rsa_tomoyan
    Permission denied (publickey,gssapi-keyex,gssapi-with-mic).
    

    その場合は、パーミッションを正しく設定しなおす。

    $ chmod 600 ~/.ssh/id_rsa_tomoyan
  1. 公開キーは接続先のサーバーに転送しておく。
    $ scp -P 22022 ~/.ssh/id_rsa.pub tomoyan@tomoyan.net:/home/tomoyan/.ssh

    id_rsa.pub                                              100%  397     0.4KB/s   00:00
    

  2. サーバー上でへ公開キーを登録する。
    $ cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys

    ※サーバー上に配置する場合はパーミッションに気をつける。(必ずHomeディレクトリのユーザーをオーナーとするように配置すること!!)

    $ sudo chown tomoyan.tomoyan ~/.ssh -R
    $ sudo chmod 700 ~/.ssh
    $ sudo chmod 600 ~/.ssh/authorized_keys

    パーミッションに誤りがあるとクライアントから接続が出来なくなります。(クライアントエラーの例)

    $ ssh -i ~/.ssh/id_rsa_tomoyan tomoyan@tomoyan.net

    Identity added: /Users/tomoyan/.ssh/id_rsa_tomoyan (/Users/tomoyan/.ssh/id_rsa_tomoyan)
    Permission denied (publickey,gssapi-keyex,gssapi-with-mic).
    

秘密キーを複数使い分ける場合は、-i オプションで秘密キーを指定する。(標準では ~/.ssh/id_rsa を使用)

$ ssh -i ~/.ssh/id_rsa_tomoyan user_name@server_name.com

※秘密キーは自分だけがアクセスできるように設定しておく

$ chmod 600 ~/.ssh/id_rsa_tomoyan

SSH エージェントを起動

$ ssh-agent bash

SSH の秘密キーをロード(複数)

$ ssh-add ~/.ssh/id_rsa
$ ssh-add ~/.ssh/id_ecdsa
$ ssh-add ~/.ssh/id_ed25519

SSH サーバーへ接続

$ ssh server_name

ロード済みの SSH 秘密キーの一覧を表示

$ ssh-add -l

ロード済みの SSH 秘密キーを一括削除

$ ssh-add -D
$ ssh-keygen -p -f ~/.ssh/id_rsa

Enter old passphrase: <- 古いパスフレーズを入力
Key has comment '.ssh/id_rsa'
Enter new passphrase (empty for no passphrase): <- 新しいパスフレーズを入力
Enter same passphrase again: <- 新しい確認用パスフレーズを入力
Your identification has been saved with the new passphrase.

$ ssh-keygen -y -f ~/.ssh/id_ed25519

Enter passphrase: <- パスフレーズを入力
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAILjRH0zA/Xy9C596VkzZCi3AMlYMvc3nkIEk8jRk+31 Tomoyan Ed25519 Test

接続先の設定を簡単に呼び出せるようにするために、ユーザー毎の設定ファイルを記述することができる。

~/.ssh/config の例:

~/.ssh/config
Host tomoyan.net
    HostName        tomoyan.net
    Port            22022
    User            tomoyan
    GatewayPorts    no
    LocalForward    5900    192.168.1.100:5900
    IdentityFile    ~/.ssh/id_rsa

LocalForward192.168.1.100:5900localhost:5900 に接続する。

OpenSSH 8.8 で Dropbear の SSH に接続出来ない場合😵

$ ssh tomoyan@old-or-dropbear

Unable to negotiate with 192.168.1.254 port 22: no matching host key type found. Their offer: ssh-rsa

OpenSSH 8.8 was released on 2021-09-26

OpenSSH 8.8リリースノートに記載の設定を、~/.ssh/configに追記する🤔

$ nano ~/.ssh/config

~/.ssh/config
Host old-or-dropbear
  HostName     192.168.1.254
  Port         22
  User         tomoyan
  GatewayPorts no
  ForwardAgent yes
  IdentityFile ~/.ssh/id_rsa_tomoyan-2023
  HostkeyAlgorithms +ssh-rsa
  PubkeyAcceptedAlgorithms +ssh-rsa

~/.ssh/configHostkeyAlgorithms +ssh-rsaPubkeyAcceptedAlgorithms +ssh-rsaを追記する🤔

sudo の設定ファイルに env_keep の設定を追記する。

$ sudo visudo

以下を追記する。

Defaults    env_keep += "SSH_AUTH_SOCK"
$ ssh tomoyan@raspberry-pi ls -al
$ ssh tomoyan@raspberry-pi 'ls -al|lolcat'

$ ssh dietpi-001 hg version

zsh:1: command not found: hg

リモートマシン (dietpi-001) の /etc/ssh/sshd_configPermitUserEnvironment yes を設定する🤔

$ ssh dietpi-001
$ sudo nano /etc/ssh/sshd_config

#PermitUserEnvironment no
PermitUserEnvironment yes

$ sudo systemctl restart sshd

リモートマシン (dietpi-001) の PATH を確認する🤔

$ ssh dietpi-001 printenv PATH

/usr/local/bin:/usr/bin:/bin:/usr/games

PATH を限定するには PATH=/usr/local/bin:/usr/bin:/bin:/usr/games:/home/dietpi/.local/bin を指定する🤔

$ ssh dietpi-001 'echo PATH=/usr/local/bin:/usr/bin:/bin:/usr/games:/home/dietpi/.local/bin > .ssh/environment'
$ ssh dietpi-001 printenv PATH

/usr/local/bin:/usr/bin:/bin:/usr/games:/home/dietpi/.local/bin

動作確認😉

$ ssh dietpi-001 hg version

Mercurial Distributed SCM (version 6.6.3)
(see https://mercurial-scm.org for more information)

Copyright (C) 2005-2023 Olivia Mackall and others
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

$ ssh tomoyan@192.168.122.22

Received disconnect from 192.168.122.22 port 22:2: Too many authentication failures
Disconnected from 192.168.122.22 port 22

Too many authentication failures のシンプルな回避方法

接続先がパスワード認証可能な場合は、一時的にパスワード認証を強制する🤔

$ ssh -o PreferredAuthentications=password tomoyan@192.168.122.22

tomoyan@192.168.122.22's password: 
Last failed login: Sun Feb  4 19:13:54 JST 2024 from 192.168.122.80 on ssh:notty
There were 2 failed login attempts since the last successful login.
Last login: Sun Feb  4 19:08:59 2024 from 192.168.122.80

$

または、一時的に鍵認証無効を強制する🤔

$ ssh -o PubkeyAuthentication=no tomoyan@192.168.122.22

tomoyan@192.168.122.22's password: 
Last failed login: Sun Feb  4 19:13:54 JST 2024 from 192.168.122.80 on ssh:notty
There were 2 failed login attempts since the last successful login.
Last login: Sun Feb  4 19:08:59 2024 from 192.168.122.80

$

または、SSH_AUTH_SOCK 変数をコマンドのコンテキスト内でのみ設定を解除すると一時的に鍵認証を無効にできる🤔

$ SSH_AUTH_SOCK= ssh tomoyan@192.168.122.22

tomoyan@192.168.122.22's password: 
Last login: Sun Feb  4 19:38:39 2024 from 192.168.122.80

$

接続先に鍵認証の設定をして、-i ~/.ssh/id_ed25519 鍵を指定する、または ~/.ssh/configIdentityFile ~/.ssh/id_ed25519 を設定する🤔

$ ssh -i ~/.ssh/id_ed25519 tomoyan@192.168.122.22

Last login: Sun Feb  4 19:42:26 2024 from 192.168.122.80

$

原因まとめ

ssh-agent は秘密鍵のパスフレーズを解除して、すぐに使えるようにしてくれているだけなので、鍵を削除したりクリアしてしまっては意味がない😅
ssh コマンドは ~/.ssh/config、または、ssh -i ~/.ssh/id_ed25519 で秘密鍵が指定されていれば、ssh-agent にロードされている秘密キーはパスフレーズの入力をスキップして使用できる🤔
接続先がパスワード認証を許可している場合 (sshd_config の PasswordAuthentication yes)、~/.ssh/config、または、ssh -o PreferredAuthentications=password でパスワード認証を明示的に指定すればよいだけである🤔
ssh-agent にロードされている秘密鍵を試行するのは、接続先の秘密鍵の指定が無くパスワード認証の指定も無い場合だけである😉
その場合は接続先の試行回数 (sshd_config の MaxAuthTries 6) を超えるとエラーになる😰

$ ssh-add -l

256 SHA256:sOCAKAgY0X4o6wXIgsagMXA0eLh8YpqpyY2utMsQN7o MGC. TomoYan Ed25519 001 (ED25519)
256 SHA256:V6dEoyQ+QSz/BuirGsq3OfcjHJH7yn9VqSUuTJ26LGE MGC. TomoYan Ed25519 002 (ED25519)
256 SHA256:WUp/OJCeo4QDVpZaJFPdGCIcVtQakcoLbRIV4ydL+30 MGC. TomoYan Ed25519 003 (ED25519)
256 SHA256:tMjEPGV5tbpcheglMYvUz6Mzn8QLUCQc/rRGHzBKkLM MGC. TomoYan Ed25519 004 (ED25519)
256 SHA256:zQihsfnpfANwuwp9utdKm9WCTLYzUfjET2CQVLuPGnM MGC. TomoYan Ed25519 005 (ED25519)
256 SHA256:MRY3hHwcUWMkUBD5askZASG7db8WILKck+ZE/rpJEF0 MGC. TomoYan Ed25519 006 (ED25519)
256 SHA256:9VoLB7OtdUXRFravLWmZiBp70LYVCmGKxNbI3pTvNWY MGC. TomoYan Ed25519 007 (ED25519)
256 SHA256:mB9ExF5tblFV56nXW7YCFPbTIEPqqUyqJWz8dYt9Dqc MGC. TomoYan Ed25519 008 (ED25519)
256 SHA256:v2t/SGt+bIGNq8rBNlFdmYIGHUsS2FsTFZebHvHNNZI MGC. TomoYan Ed25519 009 (ED25519)
256 SHA256:qIbSzQ1f/FNqyLNVcIE30nH2oUeUNZ88wEJC8eWYnY0 MGC. TomoYan Ed25519 010 (ED25519)

ssh コマンドの -v (Verbose mode) オプションを指定して実行すると見えてくるエラーの原因は…🤔

$ ssh -v tomoyan@192.168.122.22

OpenSSH_8.7p1, OpenSSL 1.1.1l  FIPS 24 Aug 2021
debug1: Reading configuration data /home/tomoyan/.ssh/config
debug1: /home/tomoyan/.ssh/config line 1: Applying options for *
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Reading configuration data /etc/ssh/ssh_config.d/50-redhat.conf
debug1: Reading configuration data /etc/crypto-policies/back-ends/openssh.config
debug1: configuration requests final Match pass
debug1: re-parsing configuration
debug1: Reading configuration data /home/tomoyan/.ssh/config
debug1: /home/tomoyan/.ssh/config line 1: Applying options for *
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Reading configuration data /etc/ssh/ssh_config.d/50-redhat.conf
debug1: Reading configuration data /etc/crypto-policies/back-ends/openssh.config
debug1: Connecting to 192.168.122.22 [192.168.122.22] port 22.
debug1: Connection established.
debug1: identity file /home/tomoyan/.ssh/id_rsa type -1
debug1: identity file /home/tomoyan/.ssh/id_rsa-cert type -1
debug1: identity file /home/tomoyan/.ssh/id_dsa type -1
debug1: identity file /home/tomoyan/.ssh/id_dsa-cert type -1
debug1: identity file /home/tomoyan/.ssh/id_ecdsa type -1
debug1: identity file /home/tomoyan/.ssh/id_ecdsa-cert type -1
debug1: identity file /home/tomoyan/.ssh/id_ecdsa_sk type -1
debug1: identity file /home/tomoyan/.ssh/id_ecdsa_sk-cert type -1
debug1: identity file /home/tomoyan/.ssh/id_ed25519 type -1
debug1: identity file /home/tomoyan/.ssh/id_ed25519-cert type -1
debug1: identity file /home/tomoyan/.ssh/id_ed25519_sk type -1
debug1: identity file /home/tomoyan/.ssh/id_ed25519_sk-cert type -1
debug1: identity file /home/tomoyan/.ssh/id_xmss type -1
debug1: identity file /home/tomoyan/.ssh/id_xmss-cert type -1
debug1: Local version string SSH-2.0-OpenSSH_8.7
debug1: Remote protocol version 2.0, remote software version OpenSSH_8.7
debug1: compat_banner: match: OpenSSH_8.7 pat OpenSSH* compat 0x04000000
debug1: Authenticating to 192.168.122.22:22 as 'tomoyan'
debug1: load_hostkeys: fopen /home/tomoyan/.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: curve25519-sha256
debug1: kex: host key algorithm: ssh-ed25519
debug1: kex: server->client cipher: aes256-gcm@openssh.com MAC: <implicit> compression: none
debug1: kex: client->server cipher: aes256-gcm@openssh.com MAC: <implicit> compression: none
debug1: kex: curve25519-sha256 need=32 dh_need=32
debug1: kex: curve25519-sha256 need=32 dh_need=32
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: SSH2_MSG_KEX_ECDH_REPLY received
debug1: Server host key: ssh-ed25519 SHA256:pC4Vh8+xYctZ3P8kKWiPk7sN5Q89oGGhWp7Krk5Y+Ag
debug1: load_hostkeys: fopen /home/tomoyan/.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 '192.168.122.22' is known and matches the ED25519 host key.
debug1: Found key in /home/tomoyan/.ssh/known_hosts:7
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: MGC. TomoYan Ed25519 001 ED25519 SHA256:sOCAKAgY0X4o6wXIgsagMXA0eLh8YpqpyY2utMsQN7o agent
debug1: Will attempt key: MGC. TomoYan Ed25519 002 ED25519 SHA256:V6dEoyQ+QSz/BuirGsq3OfcjHJH7yn9VqSUuTJ26LGE agent
debug1: Will attempt key: MGC. TomoYan Ed25519 003 ED25519 SHA256:WUp/OJCeo4QDVpZaJFPdGCIcVtQakcoLbRIV4ydL+30 agent
debug1: Will attempt key: MGC. TomoYan Ed25519 004 ED25519 SHA256:tMjEPGV5tbpcheglMYvUz6Mzn8QLUCQc/rRGHzBKkLM agent
debug1: Will attempt key: MGC. TomoYan Ed25519 005 ED25519 SHA256:zQihsfnpfANwuwp9utdKm9WCTLYzUfjET2CQVLuPGnM agent
debug1: Will attempt key: MGC. TomoYan Ed25519 006 ED25519 SHA256:MRY3hHwcUWMkUBD5askZASG7db8WILKck+ZE/rpJEF0 agent
debug1: Will attempt key: MGC. TomoYan Ed25519 007 ED25519 SHA256:9VoLB7OtdUXRFravLWmZiBp70LYVCmGKxNbI3pTvNWY agent
debug1: Will attempt key: MGC. TomoYan Ed25519 008 ED25519 SHA256:mB9ExF5tblFV56nXW7YCFPbTIEPqqUyqJWz8dYt9Dqc agent
debug1: Will attempt key: MGC. TomoYan Ed25519 009 ED25519 SHA256:v2t/SGt+bIGNq8rBNlFdmYIGHUsS2FsTFZebHvHNNZI agent
debug1: Will attempt key: MGC. TomoYan Ed25519 010 ED25519 SHA256:qIbSzQ1f/FNqyLNVcIE30nH2oUeUNZ88wEJC8eWYnY0 agent
debug1: Will attempt key: /home/tomoyan/.ssh/id_rsa 
debug1: Will attempt key: /home/tomoyan/.ssh/id_dsa 
debug1: Will attempt key: /home/tomoyan/.ssh/id_ecdsa 
debug1: Will attempt key: /home/tomoyan/.ssh/id_ecdsa_sk 
debug1: Will attempt key: /home/tomoyan/.ssh/id_ed25519 
debug1: Will attempt key: /home/tomoyan/.ssh/id_ed25519_sk 
debug1: Will attempt key: /home/tomoyan/.ssh/id_xmss 
debug1: SSH2_MSG_EXT_INFO received
debug1: kex_input_ext_info: server-sig-algs=<ssh-ed25519,sk-ssh-ed25519@openssh.com,ssh-rsa,rsa-sha2-256,rsa-sha2-512,ssh-dss,ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521,sk-ecdsa-sha2-nistp256@openssh.com,webauthn-sk-ecdsa-sha2-nistp256@openssh.com>
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mic,password
debug1: Next authentication method: gssapi-with-mic
debug1: No credentials were supplied, or the credentials were unavailable or inaccessible
No Kerberos credentials available (default cache: KCM:)


debug1: No credentials were supplied, or the credentials were unavailable or inaccessible
No Kerberos credentials available (default cache: KCM:)


debug1: Next authentication method: publickey
debug1: Offering public key: MGC. TomoYan Ed25519 001 ED25519 SHA256:sOCAKAgY0X4o6wXIgsagMXA0eLh8YpqpyY2utMsQN7o agent
debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mic,password
debug1: Offering public key: MGC. TomoYan Ed25519 002 ED25519 SHA256:V6dEoyQ+QSz/BuirGsq3OfcjHJH7yn9VqSUuTJ26LGE agent
debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mic,password
debug1: Offering public key: MGC. TomoYan Ed25519 003 ED25519 SHA256:WUp/OJCeo4QDVpZaJFPdGCIcVtQakcoLbRIV4ydL+30 agent
debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mic,password
debug1: Offering public key: MGC. TomoYan Ed25519 004 ED25519 SHA256:tMjEPGV5tbpcheglMYvUz6Mzn8QLUCQc/rRGHzBKkLM agent
debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mic,password
debug1: Offering public key: MGC. TomoYan Ed25519 005 ED25519 SHA256:zQihsfnpfANwuwp9utdKm9WCTLYzUfjET2CQVLuPGnM agent
debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mic,password
debug1: Offering public key: MGC. TomoYan Ed25519 006 ED25519 SHA256:MRY3hHwcUWMkUBD5askZASG7db8WILKck+ZE/rpJEF0 agent
Received disconnect from 192.168.122.22 port 22:2: Too many authentication failures
Disconnected from 192.168.122.22 port 22

上記の例では公開キー認証で 6 回試行のあとにサーバー側に切断(Received disconnect from …)されてエラーになっている。(ssh-agent にロードされている秘密キーを順番に試行している)

debug1: Next authentication method: publickey
debug1: Offering public key: MGC. TomoYan Ed25519 001 ED25519 SHA256:sOCAKAgY0X4o6wXIgsagMXA0eLh8YpqpyY2utMsQN7o agent
debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mic,password
debug1: Offering public key: MGC. TomoYan Ed25519 002 ED25519 SHA256:V6dEoyQ+QSz/BuirGsq3OfcjHJH7yn9VqSUuTJ26LGE agent
debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mic,password
debug1: Offering public key: MGC. TomoYan Ed25519 003 ED25519 SHA256:WUp/OJCeo4QDVpZaJFPdGCIcVtQakcoLbRIV4ydL+30 agent
debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mic,password
debug1: Offering public key: MGC. TomoYan Ed25519 004 ED25519 SHA256:tMjEPGV5tbpcheglMYvUz6Mzn8QLUCQc/rRGHzBKkLM agent
debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mic,password
debug1: Offering public key: MGC. TomoYan Ed25519 005 ED25519 SHA256:zQihsfnpfANwuwp9utdKm9WCTLYzUfjET2CQVLuPGnM agent
debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mic,password
debug1: Offering public key: MGC. TomoYan Ed25519 006 ED25519 SHA256:MRY3hHwcUWMkUBD5askZASG7db8WILKck+ZE/rpJEF0 agent
Received disconnect from 192.168.122.22 port 22:2: Too many authentication failures
Disconnected from 192.168.122.22 port 22

接続先の sshd の設定はデフォルトだと 6 回試行で切断する設定になっている。

$ sudo cat /etc/ssh/sshd_config | grep -2 MaxAuthTries

#PermitRootLogin prohibit-password
#StrictModes yes
#MaxAuthTries 6
#MaxSessions 10

  • linux/openssh/client.txt
  • 最終更新: 2024/02/27 09:03
  • by ともやん