文書の表示以前のリビジョンバックリンク文書の先頭へ この文書は読取専用です。文書のソースを閲覧することは可能ですが、変更はできません。もし変更したい場合は管理者に連絡してください。 ====== ssh クライアントの使い方 ====== ===== サーバーへの接続 ===== **単純に接続**\\ <WRAP color_term> <WRAP color_command><html><pre> <font color="#0087FF"><b>$</b></font> <font color="#26A269">ssh</font> user_name@server_name.com </pre></html></WRAP> </WRAP> **ポートを指定して接続**\\ <WRAP color_term> <WRAP color_command><html><pre> <font color="#0087FF"><b>$</b></font> <font color="#26A269">ssh</font> user_name@server_name.com <font color="#A347BA">-p22022</font> </pre></html></WRAP> </WRAP> **接続先へポートフォワード**\\ ローカルの8080ポートへの要求をリモートのlocalhost:80に転送 <WRAP color_term> <WRAP color_command><html><pre> <font color="#0087FF"><b>$</b></font> <font color="#26A269">ssh</font> user_name@server_name.com <font color="#A347BA">-L10080:localhost:80</font> </pre></html></WRAP> </WRAP> \\ ローカルの1022ポートへの要求をリモートの192.168.1.1:22に転送 <WRAP color_term> <WRAP color_command><html><pre> <font color="#0087FF"><b>$</b></font> <font color="#26A269">ssh</font> user_name@server_name.com <font color="#A347BA">-L1022:192.168.1.1:22</font> </pre></html></WRAP> </WRAP> ===== 公開/秘密キーのペアの生成 ===== Linux or Mac では ssh-keygen を使用して、公開/秘密キーのペアを生成する。\\ (-C オプションでコメントを付加しておくとよい)\\ <html><code>-t</code></html> オプションには暗号タイプを指定する。\\ <html><code>-b</code></html> オプションには暗号強度の bit 数を指定する。\\ **ED25519 の場合**\\ <WRAP color_term> <WRAP color_command><html><pre> <font color="#0087FF"><b>$</b></font> <font color="#26A269">ssh-keygen</font> <font color="#A347BA">-t</font> ed25519 <font color="#A347BA">-f</font> ~/.ssh/id_ed25519_tomoyan <font color="#A347BA">-C</font> <font color="#A2734C">"Tomoyan Ed25519"</font> </pre></html></WRAP> <WRAP color_result><html><pre> 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]-----+ </pre></html></WRAP> </WRAP> **ECDSA の場合**\\ <WRAP color_term> <WRAP color_command><html><pre> <font color="#0087FF"><b>$</b></font> <font color="#26A269">ssh-keygen</font> <font color="#A347BA">-t</font> ecdsa <font color="#A347BA">-b</font> 521 <font color="#A347BA">-f</font> ~/.ssh/id_ecdsa_tomoyan <font color="#A347BA">-C</font> <font color="#A2734C">"Tomoyan ECDSA"</font> </pre></html></WRAP> <WRAP color_result><html><pre> 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]-----+ </pre></html></WRAP> </WRAP> **RSA の場合**\ <WRAP color_term> <WRAP color_command><html><pre> <font color="#0087FF"><b>$</b></font> <font color="#26A269">ssh-keygen</font> <font color="#A347BA">-t</font> rsa <font color="#A347BA">-b</font> 2048 <font color="#A347BA">-f</font> ~/.ssh/id_rsa_tomoyan <font color="#A347BA">-C</font> <font color="#A2734C">"tomoyan RSA"</font> </pre></html></WRAP> <WRAP color_result><html><pre> 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]-----+ </pre></html></WRAP> </WRAP> 秘密キーはパーミッション: <nowiki>600(rw- --- ---)</nowiki>で ~/.ssh/id_rsa_tomoyan に生成される。\\ 公開キーはパーミッション: <nowiki>644(rw- r-- r--)</nowiki>で ~/.ssh/id_rsa_tomoyan.pub に生成される。\\ \\ 他からコピーしてきた場合など、クライアント側の秘密キーのパーミッションが適切に設定されていない場合は、警告が表示されて接続できないことがある。(以下は Mac OS X の警告の例) <WRAP color_term> <WRAP color_result><html><pre> @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @ 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). </pre></html></WRAP> </WRAP> その場合は、パーミッションを正しく設定しなおす。 <WRAP color_term> <WRAP color_command><html><pre> <font color="#0087FF"><b>$</b></font> <font color="#26A269">chmod</font> 600 <u style="text-decoration-style:solid">~/.ssh/id_rsa_tomoyan</u> </pre></html></WRAP> </WRAP> ===== 公開キーの登録 ===== - 公開キーは接続先のサーバーに転送しておく。<WRAP prewrap 100%> <WRAP color_term> <WRAP color_command><code> $ scp -P 22022 ~/.ssh/id_rsa.pub tomoyan@tomoyan.net:/home/tomoyan/.ssh </code></WRAP> <WRAP color_result><html><pre> id_rsa.pub 100% 397 0.4KB/s 00:00 </pre></html></WRAP> </WRAP> </WRAP> - サーバー上でへ公開キーを登録する。<WRAP prewrap 100%> <WRAP color_term> <WRAP color_command><code> $ cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys </code></WRAP> </WRAP> ※サーバー上に配置する場合はパーミッションに気をつける。(必ずHomeディレクトリのユーザーをオーナーとするように配置すること!!) <WRAP color_term> <WRAP color_command><code> $ sudo chown tomoyan.tomoyan ~/.ssh -R $ sudo chmod 700 ~/.ssh $ sudo chmod 600 ~/.ssh/authorized_keys </code></WRAP> </WRAP> パーミッションに誤りがあるとクライアントから接続が出来なくなります。(クライアントエラーの例) <WRAP color_term> <WRAP color_command><code> $ ssh -i ~/.ssh/id_rsa_tomoyan tomoyan@tomoyan.net </code></WRAP> <WRAP color_result><html><pre> Identity added: /Users/tomoyan/.ssh/id_rsa_tomoyan (/Users/tomoyan/.ssh/id_rsa_tomoyan) Permission denied (publickey,gssapi-keyex,gssapi-with-mic). </pre></html></WRAP> </WRAP> </WRAP> ===== 秘密キーを指定して接続 ===== <WRAP prewrap 100%> 秘密キーを複数使い分ける場合は、-i オプションで秘密キーを指定する。(標準では ~/.ssh/id_rsa を使用) <WRAP color_term> <WRAP color_command><code> $ ssh -i ~/.ssh/id_rsa_tomoyan user_name@server_name.com </code></WRAP> </WRAP> ※秘密キーは自分だけがアクセスできるように設定しておく <WRAP color_term> <WRAP color_command><code> $ chmod 600 ~/.ssh/id_rsa_tomoyan </code></WRAP> </WRAP> </WRAP> ===== 秘密キーをロードしておいて自動接続 ===== <WRAP prewrap 100%> SSH エージェントを起動\\ <WRAP color_term> <WRAP color_command><code> $ ssh-agent bash </code></WRAP> </WRAP> SSH の秘密キーをロード(複数)\\ <WRAP color_term> <WRAP color_command><code> $ ssh-add ~/.ssh/id_rsa $ ssh-add ~/.ssh/id_ecdsa $ ssh-add ~/.ssh/id_ed25519 </code></WRAP> </WRAP> SSH サーバーへ接続 <WRAP color_term> <WRAP color_command><code> $ ssh server_name </code></WRAP> </WRAP> ロード済みの SSH 秘密キーの一覧を表示\\ <WRAP color_term> <WRAP color_command><code> $ ssh-add -l </code></WRAP> </WRAP> ロード済みの SSH 秘密キーを一括削除\\ <WRAP color_term> <WRAP color_command><code> $ ssh-add -D </code></WRAP> </WRAP> </WRAP> ===== 秘密キーのパスフレーズ変更 ===== <WRAP color_term> <WRAP color_command><code> $ ssh-keygen -p -f ~/.ssh/id_rsa </code></WRAP> <WRAP color_result><html><pre> 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. </pre></html></WRAP> </WRAP> ===== 秘密キーから公開キーを出力 ===== <WRAP color_term> <WRAP color_command><code> $ ssh-keygen -y -f ~/.ssh/id_ed25519 </code></WRAP> <WRAP color_result><html><pre> Enter passphrase: <- パスフレーズを入力 ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAILjRH0zA/Xy9C596VkzZCi3AMlYMvc3nkIEk8jRk+31 Tomoyan Ed25519 Test </pre></html></WRAP> </WRAP> ===== 接続オプションを省略 ===== 接続先の設定を簡単に呼び出せるようにするために、ユーザー毎の設定ファイルを記述することができる。\\ \\ ~/.ssh/config の例: <WRAP color_term> <WRAP color_mincode><code autoconf ~/.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 </code></WRAP> </WRAP> ※**LocalForward** は **192.168.1.100:5900** を **localhost:5900** に接続する。\\ \\ **OpenSSH 8.8 で Dropbear の SSH に接続出来ない場合😵**\\ <WRAP color_term> <WRAP color_command><html><pre> $ ssh tomoyan@old-or-dropbear </pre></html></WRAP> <WRAP color_command><html><pre> Unable to negotiate with 192.168.1.254 port 22: no matching host key type found. Their offer: ssh-rsa </pre></html></WRAP> </WRAP> [[https://www.openssh.com/txt/release-8.8|OpenSSH 8.8 was released on 2021-09-26]]\\ \\ OpenSSH 8.8リリースノートに記載の設定を、<html><code>~/.ssh/config</code></html>に追記する🤔\\ <WRAP color_term> <WRAP color_command><html><pre> $ nano ~/.ssh/config </pre></html></WRAP> <WRAP color_mincode><code autoconf ~/.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 </code></WRAP> </WRAP> ※<html><code>~/.ssh/config</code></html>に<html><code>HostkeyAlgorithms +ssh-rsa</code></html>と<html><code>PubkeyAcceptedAlgorithms +ssh-rsa</code></html>を追記する🤔\\ ===== sudo で Agent Forward する方法 ===== <WRAP prewrap 100%> sudo の設定ファイルに env_keep の設定を追記する。 <WRAP color_term> <WRAP color_command><code> $ sudo visudo </code></WRAP> </WRAP> 以下を追記する。 <code> Defaults env_keep += "SSH_AUTH_SOCK" </code> </WRAP> ===== リモートマシンでコマンド実行 ===== <WRAP color_term> <WRAP color_command><code> $ ssh tomoyan@raspberry-pi ls -al </code></WRAP> </WRAP> <WRAP color_term> <WRAP colot_command><code> $ ssh tomoyan@raspberry-pi 'ls -al|lolcat' </code></WRAP> </WRAP> ==== リモートマシンでコマンド実行できない場合😥 ==== <WRAP color_term> <WRAP color_command><html><pre> <font color="#0087FF"><b>$</b></font> <font color="#26A269">ssh</font> dietpi-001 hg<font color="#999999"> version</font> </pre></html></WRAP> <WRAP color_result><html><pre> zsh:1: command not found: hg </pre></html></WRAP> </WRAP> リモートマシン (dietpi-001) の <html><code>/etc/ssh/sshd_config</code></html> に <html><code>PermitUserEnvironment yes</code></html> を設定する🤔\\ <WRAP color_term> <WRAP color_command><html><pre> <font color="#0087FF"><b>$</b></font> <font color="#26A269">ssh</font> dietpi-001 <font color="#0087FF"><b>$</b></font> <font color="#26A269">sudo</font> <font color="#26A269">nano</font><font color="#999999"> </font><font color="#999999"><u style="text-decoration-style:single">/etc/ssh/sshd_config</u></font> </pre></html></WRAP> <WRAP color_result><html><pre> <font color="#2AA1B3">#PermitUserEnvironment no</font> PermitUserEnvironment yes </pre></html></WRAP> <WRAP color_command><html><pre> <font color="#0087FF"><b>$</b></font> <font color="#26A269">sudo</font> <font color="#26A269">systemctl</font><font color="#999999"> restart sshd</font> </pre></html></WRAP> </WRAP> リモートマシン (dietpi-001) の **PATH** を確認する🤔\\ <WRAP color_term> <WRAP color_command><html><pre> <font color="#0087FF"><b>$</b></font> <font color="#26A269">ssh</font> dietpi-001 printenv PATH </pre></html></WRAP> <WRAP color_result><html><pre> /usr/local/bin:/usr/bin:/bin:/usr/games </pre></html></WRAP> </WRAP> **PATH** を限定するには <html><code>PATH=/usr/local/bin:/usr/bin:/bin:/usr/games:/home/dietpi/.local/bin</code></html> を指定する🤔\\ <WRAP color_term> <WRAP color_command><html><pre> <font color="#0087FF"><b>$</b></font> <font color="#26A269">ssh</font> dietpi-001 <font color="#A2734C">'echo PATH=/usr/local/bin:/usr/bin:/bin:/usr/games:/home/dietpi/.local/bin > .ssh/environment'</font> <font color="#0087FF"><b>$</b></font> <font color="#26A269">ssh</font> dietpi-001 printenv PATH </pre></html></WRAP> <WRAP color_result><html><pre> /usr/local/bin:/usr/bin:/bin:/usr/games:/home/dietpi/.local/bin </pre></html></WRAP> </WRAP> 動作確認😉\\ <WRAP color_term> <WRAP color_command><html><pre> <font color="#0087FF"><b>$</b></font> <font color="#26A269">ssh</font> dietpi-001 hg version </pre></html></WRAP> <WRAP color_result><html><pre> 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. </pre></html></WRAP> </WRAP> ===== リモートマシンから切断されて ssh がフリーズする🤪 ===== ssh エスケープ文字 <html><code>~</code></html> につづけて <html><code>.</code></html> で切断できる😉\\ <WRAP color_term> <WRAP color_command><html><pre> <font color="#0087FF"><b>$</b></font> <font color="#C01C28"><b>~.</b></font> </pre></html></WRAP> <WRAP color_result><html><pre> Connection to wicked-beat closed. </pre></html></WRAP> </WRAP> ===== トラブルシューティング ===== ==== Fedora 41 で RSA 鍵認証が失敗する場合 ==== 参考: [[https://discussion.fedoraproject.org/t/fedora-41-ssh-to-rhel6-error-in-libcrypto/135999/11|Fedora 41: SSH to RHEL6 - error in libcrypto - Fedora Discussion]]\\ <WRAP color_term> <WRAP color_command><html><pre> <font color="#0087FF"><b>$</b></font> <font color="#26A269">ssh</font> tomoyan-wrt </pre></html></WRAP> <WRAP color_result><html><pre> ssh_dispatch_run_fatal: Connection to 192.168.1.1 port 22: error in libcrypto </pre></html></WRAP> </WRAP> 暗号化ポリシーを FEDORA40 に変更してから再接続する🤔\\ <WRAP color_term> <WRAP color_command><html><pre> <font color="#0087FF"><b>$</b></font> <font color="#26A269"><u style="text-decoration-style:solid">sudo</u></font> <font color="#26A269">update-crypto-policies</font> <font color="#A347BA">--set</font> FEDORA40 </pre></html></WRAP> <WRAP color_result><html><pre> Setting system policy to FEDORA40 Note: System-wide crypto policies are applied on application start-up. It is recommended to restart the system for the change of policies to fully take place. </pre></html></WRAP> <WRAP color_command><html><pre> <font color="#0087FF"><b>$</b></font> <font color="#26A269">ssh</font> tomoyan-wrt </pre></html></WRAP> <WRAP color_result><html><pre> Enter passphrase for key '/home/tomoyan/.ssh/id_rsa_tomoyan-2025': BusyBox v1.30.1 () built-in shell (ash) _______ ________ __ | |.-----.-----.-----.| | | |.----.| |_ | - || _ | -__| || | | || _|| _| |_______|| __|_____|__|__||________||__| |____| |__| W I R E L E S S F R E E D O M ----------------------------------------------------- OpenWrt 19.07.8, r11364-ef56c85848 ----------------------------------------------------- root@TomoyanWRT:~# </pre></html></WRAP> </WRAP> ==== SSH 接続しようとすると「Too many authentication failures」で切断される😢 ==== <WRAP color_term> <WRAP color_command><html><pre> <font color="#FF8700"><b>$</b></font> <font color="#26A269">ssh</font> tomoyan@192.168.122.22 </pre></html></WRAP> <WRAP color_result><html><pre> Received disconnect from 192.168.122.22 port 22:2: Too many authentication failures Disconnected from 192.168.122.22 port 22 </pre></html></WRAP> </WRAP> === Too many authentication failures のシンプルな回避方法 === 接続先がパスワード認証可能な場合は、一時的にパスワード認証を強制する🤔\\ <WRAP color_term> <WRAP color_command><html><pre> <font color="#FF8700"><b>$</b></font> <font color="#26A269">ssh</font> <font color="#A347BA">-o</font> PreferredAuthentications=password tomoyan@192.168.122.22 </pre></html></WRAP> <WRAP color_result><html><pre> 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 </pre></html></WRAP> <WRAP color_command><html><pre> <font color="#FF8700"><b>$</b></font> </pre></html></WRAP> </WRAP> または、一時的に鍵認証無効を強制する🤔\\ <WRAP color_term> <WRAP color_command><html><pre> <font color="#FF8700"><b>$</b></font> <font color="#26A269">ssh</font> <font color="#A347BA">-o</font> PubkeyAuthentication=no tomoyan@192.168.122.22 </pre></html></WRAP> <WRAP color_result><html><pre> 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 </pre></html></WRAP> <WRAP color_command><html><pre> <font color="#FF8700"><b>$</b></font> </pre></html></WRAP> </WRAP> または、<html><code>SSH_AUTH_SOCK</code></html> 変数をコマンドのコンテキスト内でのみ設定を解除すると一時的に鍵認証を無効にできる🤔\\ <WRAP color_term> <WRAP color_command><html><pre> <font color="#FF8700"><b>$</b></font> SSH_AUTH_SOCK= <font color="#26A269">ssh</font> tomoyan@192.168.122.22 </pre></html></WRAP> <WRAP color_result><html><pre> tomoyan@192.168.122.22's password: Last login: Sun Feb 4 19:38:39 2024 from 192.168.122.80 </pre></html></WRAP> <WRAP color_command><html><pre> <font color="#FF8700"><b>$</b></font> </pre></html></WRAP> </WRAP> 接続先に鍵認証の設定をして、<html><code>-i ~/.ssh/id_ed25519</code></html> 鍵を指定する、または <html><code>~/.ssh/config</code></html> で <html><code>IdentityFile ~/.ssh/id_ed25519</code></html> を設定する🤔\\ <WRAP color_term> <WRAP color_command><html><pre><font color="#FF8700"><b>$</b></font> <font color="#26A269">ssh</font> <font color="#A347BA">-i</font> <u style="text-decoration-style:single">~/.ssh/id_ed25519</u> tomoyan@192.168.122.22 </pre></html></WRAP> <WRAP color_result><html><pre> Last login: Sun Feb 4 19:42:26 2024 from 192.168.122.80 </pre></html></WRAP> <WRAP color_command><html><pre> <font color="#FF8700"><b>$</b></font> </pre></html></WRAP> </WRAP> === 原因まとめ === ssh-agent は秘密鍵のパスフレーズを解除して、すぐに使えるようにしてくれているだけなので、__鍵を削除したりクリアしてしまっては意味がない__😅\\ ssh コマンドは <html><code>~/.ssh/config</code></html>、または、<html><code>ssh -i ~/.ssh/id_ed25519</code></html> で秘密鍵が指定されていれば、ssh-agent にロードされている秘密キーはパスフレーズの入力をスキップして使用できる🤔\\ 接続先がパスワード認証を許可している場合 (sshd_config の PasswordAuthentication yes)、<html><code>~/.ssh/config</code></html>、または、<html><code>ssh -o PreferredAuthentications=password</code></html> でパスワード認証を明示的に指定すればよいだけである🤔\\ ssh-agent にロードされている秘密鍵を試行するのは、__接続先の秘密鍵の指定が無くパスワード認証の指定も無い場合__だけである😉\\ その場合は接続先の試行回数 (sshd_config の MaxAuthTries 6) を超えるとエラーになる😰\\ <WRAP color_term> <WRAP color_command><html><pre> <font color="#FF8700"><b>$</b></font> <font color="#26A269">ssh-add</font> <font color="#A347BA">-l</font> </pre></html></WRAP> <WRAP color_result><html><pre> 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) </pre></html></WRAP> </WRAP> ssh コマンドの **-v (Verbose mode)** オプションを指定して実行すると見えてくるエラーの原因は...🤔\\ <WRAP color_term> <WRAP color_command><html><pre> <font color="#FF8700"><b>$</b></font> <font color="#26A269">ssh</font> <font color="#A347BA">-v</font> tomoyan@192.168.122.22 </pre></html></WRAP> <WRAP color_result_long><html><pre> 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 </pre></html></WRAP> </WRAP> 上記の例では公開キー認証で 6 回試行のあとにサーバー側に切断**(Received disconnect from ...)**されてエラーになっている。(ssh-agent にロードされている秘密キーを順番に試行している)\\ <WRAP color_result><html><pre> 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 </pre></html></WRAP> 接続先の sshd の設定はデフォルトだと 6 回試行で切断する設定になっている。\\ <WRAP color_term> <WRAP color_command><html><pre> <font color="#FF8700"><b>$</b></font> <font color="#26A269"><u style="text-decoration-style:single">sudo</u></font> <font color="#26A269">cat</font> <u style="text-decoration-style:single">/etc/ssh/sshd_config</u> <font color="#13496F"><b>|</b></font> <font color="#26A269">grep</font> <font color="#A347BA">-2</font> MaxAuthTries </pre></html></WRAP> <WRAP color_result><html><pre> #PermitRootLogin prohibit-password #StrictModes yes #<b class=RED>MaxAuthTries</b> 6 #MaxSessions 10 </pre></html></WRAP> </WRAP> ===== 参考文献 ===== [[https://qiita.com/angel_p_57/items/a1dc4e9c0b18a23c5242|電子署名EdDSA(ed25519)の数的構造 - Qiita]]\\ [[https://http2.try-and-test.net/ecdsa.html|暗号スイートの暗号強度と、公開鍵のビット数の設定、及びRSAとECDHEでサーバ負荷の比較 - Apache 2.4系でHTTP/2対応サーバを構築してみるテスト。]]\\ [[https://kaworu.jpn.org/security/ssh%E6%8E%A5%E7%B6%9A%E3%81%8C%E8%87%AA%E5%8B%95%E5%88%87%E6%96%AD%E3%81%95%E3%82%8C%E3%82%8B%E5%A0%B4%E5%90%88%E3%81%AE%E5%9B%9E%E9%81%BF%E6%96%B9%E6%B3%95|ssh接続が自動切断される場合の回避方法 - セキュリティ]]\\ [[so>/questions/26258157/disable-ssh-agent-with-command-line-option|Disable SSH agent with command line option - Stack Overflow]] [[gtr>https://stackoverflow.com/questions/26258157/disable-ssh-agent-with-command-line-option|翻訳]]\\ [[https://discussion.fedoraproject.org/t/fedora-41-ssh-to-rhel6-error-in-libcrypto/135999/10|Fedora 41: SSH to RHEL6 - error in libcrypto - Fedora Discussion]]\\ ==== 付録 ==== [[tw>tomoyan596sp/status/1461182417796931585|ということで、Windowsで作成したOpenSSHの秘密鍵が、LinuxのOpenSSHでInvalid Formatって言われちゃったら、Linux上のputtygenで一旦ppk形式の秘密鍵に変換して、それをまたputtygenでOpenSSH形式に戻してあげると生き返ります😇🤣笑 / Twitter]]\\ [[tw>tomoyan596sp/status/1470389755863244801|$ ssh skv001v6Authenticated to https://t.co/OVsDxtRcrc ([2401:2500:102:3014:153:126:156:195]:22) using "publickey".😊$ ssh skv001v4Received disconnect from 153.126.156.195 port 22:2: Too many authentication failuresDisconnected from 153.126.156.195 port 22🤔IPv4 <--> IPv6🤯 / Twitter]]\\ [[tw>tomoyan596sp/status/1473396130495217665|もしも、接続先のサーバーがパスワード認証なのにssh-agentの鍵の一覧を試行してしまってエラーになるなら、-o オプションで認証タイプをpasswordに限定できます🤤 $ ssh tomoyan@192.168.122.22 -o PreferredAuthentications=password]]\\ [[tw>tomoyan596sp/status/1625657399150522368|ssh の GatewayPorts yes/no ってなに?🤔ポートフォワードしているときに...ポートをループバックアドレス(127.0.0.1)にバインドするか、ワイルドカードアドレス(0.0.0.0)にバインドするのかです😊$ info ssh_config より...]]\\ [[tw>tomoyan596sp/status/1630412101805285376|DropbearのSSHはこれやらないと繋がらないらしい😅たぶんRaspberry PiのDietPiでOpenSSH Serverにしていない場合のDropbearも繋がらないかも🤔~/.ssh/configHost old-host HostkeyAlgorithms +ssh-rsa PubkeyAcceptedAlgorithms +ssh-rsa]]\\ linux/openssh/client.txt 最終更新: 2025/03/02 06:13by ともやん