linux:openssh:client

差分

このページの2つのバージョン間の差分を表示します。

この比較画面へのリンク

両方とも前のリビジョン 前のリビジョン
次のリビジョン
前のリビジョン
linux:openssh:client [2024/02/04 20:04] – [原因まとめ] ともやんlinux:openssh:client [2025/09/25 13:11] (現在) – [SSH 接続を一定期間放置すると Read from remote host xxx: Connection reset by peer が発生して切れる😅] ともやん
行 2: 行 2:
  
 ===== サーバーへの接続 ===== ===== サーバーへの接続 =====
-<WRAP prewrap 100%> 
 **単純に接続**\\ **単純に接続**\\
 <WRAP color_term> <WRAP color_term>
-<WRAP color_command><code+<WRAP color_command><html><pre
-$ ssh user_name@server_name.com +<font color="#0087FF"><b>$</b></font> <font color="#26A269">ssh</font> user_name@server_name.com 
-</code></WRAP>+</pre></html></WRAP>
 </WRAP> </WRAP>
  
 **ポートを指定して接続**\\ **ポートを指定して接続**\\
 <WRAP color_term> <WRAP color_term>
-<WRAP color_command><code+<WRAP color_command><html><pre
-$ ssh user_name@server_name.com -p22022 +<font color="#0087FF"><b>$</b></font> <font color="#26A269">ssh</font> user_name@server_name.com <font color="#A347BA">-p22022</font> 
-</code></WRAP>+</pre></html></WRAP>
 </WRAP> </WRAP>
  
行 20: 行 19:
 ローカルの8080ポートへの要求をリモートのlocalhost:80に転送 ローカルの8080ポートへの要求をリモートのlocalhost:80に転送
 <WRAP color_term> <WRAP color_term>
-<WRAP color_command><code+<WRAP color_command><html><pre
-$ ssh user_name@server_name.com -L10080:localhost:80 +<font color="#0087FF"><b>$</b></font> <font color="#26A269">ssh</font> user_name@server_name.com <font color="#A347BA">-L10080:localhost:80</font> 
-</code></WRAP>+</pre></html></WRAP>
 </WRAP> </WRAP>
 \\ \\
 ローカルの1022ポートへの要求をリモートの192.168.1.1:22に転送 ローカルの1022ポートへの要求をリモートの192.168.1.1:22に転送
 <WRAP color_term> <WRAP color_term>
-<WRAP color_command><code+<WRAP color_command><html><pre
-$ ssh user_name@server_name.com -L1022:192.168.1.1:22 +<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> 
-</code></WRAP>+</pre></html></WRAP>
 </WRAP> </WRAP>
  
-</WRAP>+===== 公開/秘密キーのペアの生成 ===== 
 +Linux or Mac では ssh-keygen を使用して、公開/秘密キーのペアを生成する。\\ 
 +(-C オプションでコメントを付加しておくとよい)\\ 
 +<html><code>-t</code></html> オプションには暗号タイプを指定する。\\ 
 +<html><code>-b</code></htmlオプションには暗号強度の bit 数を指定する。\\
  
-===== 公開/秘密キーのペアの生成 ===== +**ED25519 の場合**\\
-<WRAP prewrap 100%> +
-  Linux or Mac では ssh-keygen を使用して、公開/秘密キーのペアを生成する。\\ (-C オプションでコメントを付加しておくとよい)\\ -t オプションには暗号タイプを指定する。\\ -b オプションには暗号強度の bit 数を指定する。\\ \\ <WRAP prewrap 100%> +
-ED25519 の場合+
 <WRAP color_term> <WRAP color_term>
-<WRAP color_command><code+<WRAP color_command><html><pre
-$ ssh-keygen -t ed25519 -f ~/.ssh/id_ed25519_tomoyan -C "Tomoyan Ed25519" +<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">&quot;Tomoyan Ed25519&quot;</font> 
-</code></WRAP>+</pre></html></WRAP>
 <WRAP color_result><html><pre> <WRAP color_result><html><pre>
 Generating public/private ed25519 key pair. Generating public/private ed25519 key pair.
行 65: 行 65:
 </WRAP> </WRAP>
  
-ECDSA の場合+**ECDSA の場合**\\
 <WRAP color_term> <WRAP color_term>
-<WRAP color_command><code+<WRAP color_command><html><pre
-$ ssh-keygen -t ecdsa -b 521 -f ~/.ssh/id_ecdsa_tomoyan -C "Tomoyan ECDSA" +<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">&quot;Tomoyan ECDSA&quot;</font> 
-</code></WRAP>+</pre></html></WRAP>
 <WRAP color_result><html><pre> <WRAP color_result><html><pre>
 Generating public/private ecdsa key pair. Generating public/private ecdsa key pair.
行 93: 行 93:
 </WRAP> </WRAP>
  
-RSA の場合+**RSA の場合**\
 <WRAP color_term> <WRAP color_term>
-<WRAP color_command><code+<WRAP color_command><html><pre
-$ ssh-keygen -t rsa -b 2048 -f ~/.ssh/id_rsa_tomoyan -C "tomoyan rsa+<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">&quot;tomoyan RSA&quot;</font> 
-</code></WRAP>+</pre></html></WRAP>
 <WRAP color_result><html><pre> <WRAP color_result><html><pre>
 Generating public/private rsa key pair. Generating public/private rsa key pair.
行 120: 行 120:
 </pre></html></WRAP> </pre></html></WRAP>
 </WRAP> </WRAP>
 +
 秘密キーはパーミッション: <nowiki>600(rw- --- ---)</nowiki>で ~/.ssh/id_rsa_tomoyan に生成される。\\ 秘密キーはパーミッション: <nowiki>600(rw- --- ---)</nowiki>で ~/.ssh/id_rsa_tomoyan に生成される。\\
 公開キーはパーミッション: <nowiki>644(rw- r-- r--)</nowiki>で ~/.ssh/id_rsa_tomoyan.pub に生成される。\\ \\ 公開キーはパーミッション: <nowiki>644(rw- r-- r--)</nowiki>で ~/.ssh/id_rsa_tomoyan.pub に生成される。\\ \\
行 137: 行 138:
 その場合は、パーミッションを正しく設定しなおす。 その場合は、パーミッションを正しく設定しなおす。
 <WRAP color_term> <WRAP color_term>
-<WRAP color_command><code+<WRAP color_command><html><pre
-$ chmod 600 ~/.ssh/id_rsa_tomoyan +<font color="#0087FF"><b>$</b></font> <font color="#26A269">chmod</font> 600 <u style="text-decoration-style:solid">~/.ssh/id_rsa_tomoyan</u> 
-</code></WRAP> +</pre></html></WRAP>
-</WRAP> +
- +
-</WRAP>+
 </WRAP> </WRAP>
  
行 329: 行 327:
  
 ===== リモートマシンでコマンド実行 ===== ===== リモートマシンでコマンド実行 =====
-<WRAP prewrap 100%> 
 <WRAP color_term> <WRAP color_term>
 <WRAP color_command><code> <WRAP color_command><code>
行 342: 行 339:
 </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">&apos;echo PATH=/usr/local/bin:/usr/bin:/bin:/usr/games:/home/dietpi/.local/bin &gt; .ssh/environment&apos;</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> </WRAP>
  
 ===== トラブルシューティング ===== ===== トラブルシューティング =====
 +
 +==== SSH 接続を一定期間放置すると Read from remote host xxx: Connection reset by peer が発生して切れる😅 ====
 +<WRAP color_term>
 +<WRAP color_result><html><pre>
 +Read from remote host xxx: Connection reset by peer
 +Connection to xxx closed.
 +client_loop: send disconnect: Broken pipe
 +</pre></html></WRAP>
 +</WRAP>
 +
 +クライアント側での設定 (''~/.ssh/config'')\\
 +<WRAP color_term>
 +<WRAP color_command><html><pre>
 +<font color="#0087FF"><b>$</b></font> <font color="#26A269">sed</font> <font color="#A347BA">-i</font> <font color="#A2734C">&apos;1i Host *\n    ServerAliveInterval 60\n    ServerAliveCountMax 3\n&apos;</font> <u style="text-decoration-style:solid">~/.ssh/config</u>
 +<font color="#0087FF"><b>$</b></font> <font color="#26A269">bat</font> <u style="text-decoration-style:solid">~/.ssh/config</u>
 +</pre></html></WRAP>
 +<WRAP color_result><html><pre class=Bat>
 +<font color="#839496">   1</font> <font color="#F92672">Host</font><font color="#F8F8F2"> </font><font color="#F92672">*</font>
 +<font color="#839496">   2</font> <font color="#F8F8F2">    </font><font color="#F92672">ServerAliveInterval</font><font color="#F8F8F2"> </font><font color="#BE84FF">60</font>
 +<font color="#839496">   3</font> <font color="#F8F8F2">    </font><font color="#F92672">ServerAliveCountMax</font><font color="#F8F8F2"> </font><font color="#BE84FF">3</font>
 +<font color="#839496">   4</font> 
 +</pre></html></WRAP>
 +</WRAP>
 +  * ''sed -i'': ファイルをインプレース編集(上書き保存)。バックアップしたい場合は -i.bak でバックアップ作成。
 +  * ''1i'': ファイルの1行目に挿入。
 +  * ''Host *\n    ServerAliveInterval 60\n    ServerAliveCountMax 3\n'': 挿入する内容。''\n'' で改行、インデント(スペース 4 つ)で設定を記述。
 +  * ''~/.ssh/config'': 対象ファイル。
 +
 +  * ''ServerAliveInterval 60'': 60 秒ごとにクライアントにパケット送信。
 +  * ''ServerAliveCountMax 5'': 5 回応答なしで切断。
 +
 +[[linux:tmux|tmux]] 内では ssh 接続が持続する🤔\\
 +理由は ''status-interval 15'' だから😅\\
 +ステータスバーに ''#[fg=green]%H:%M'' (時計)が 15 秒おきに接続を維持してる😂\\
 +<WRAP color_term>
 +<WRAP color_command><html><pre>
 +<font color="#0087FF"><b>$</b></font> <font color="#26A269">tmux</font> show-options <font color="#A347BA">-g</font> status-interval
 +</pre></html></WRAP>
 +<WRAP color_result><html><pre>
 +status-interval 15
 +</pre></html></WRAP>
 +</WRAP>
 +
 +=== サーバーのデフォルト設定の問題 ===
 +<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">cat</font> <u style="text-decoration-style:solid">/etc/ssh/sshd_config</u> <font color="#12488B"><b>|</b></font> <font color="#26A269">bat</font> <font color="#A347BA">-l</font> conf <font color="#A347BA">-H123</font> <font color="#A347BA">-H126:127</font>
 +</pre></html></WRAP>
 +<WRAP color_result><html><pre>
 +<font color="#839496"> 107</font> <font color="#75715E">#PermitTTY yes</font>
 +<font color="#839496"> 108</font> <font color="#75715E">#PrintMotd yes</font>
 +<font color="#839496"> 109</font> <font color="#75715E">#PrintLastLog yes</font>
 +<font color="#839496"> 110</font> <span style="background-color:#333333"><font color="#75715E">#TCPKeepAlive yes</font></span><span style="background-color:#333333">                                                                                                    </span>
 +<font color="#839496"> 111</font> <font color="#75715E">#PermitUserEnvironment no</font>
 +<font color="#839496"> 112</font> <font color="#75715E">#Compression delayed</font>
 +<font color="#839496"> 113</font> <span style="background-color:#333333"><font color="#75715E">#ClientAliveInterval 0</font></span><span style="background-color:#333333">                                                                                               </span>
 +<font color="#839496"> 114</font> <span style="background-color:#333333"><font color="#75715E">#ClientAliveCountMax 3</font></span><span style="background-color:#333333">                                                                                               </span>
 +<font color="#839496"> 115</font> <font color="#75715E">#UseDNS no</font>
 +<font color="#839496"> 116</font> <font color="#75715E">#PidFile /var/run/sshd.pid</font>
 +<font color="#839496"> 117</font> <font color="#75715E">#MaxStartups 10:30:100</font>
 +</pre></html></WRAP>
 +</WRAP>
 +  * TCPKeepAlive yes:
 +    * 意味: OSレベルのTCPキープアライブを有効(デフォルト間隔はOS依存、通常7200秒=2時間)。
 +    * 影響: TCP層で接続を維持するが、間隔が長すぎる(例: Fedoraのデフォルト ''net.ipv4.tcp_keepalive_time = 7200'')ため、ファイアウォール/ロードバランサの短いタイムアウト(例: 60秒)に対応できない。
 +    * 問題: セキュリティリスク(スプーフィングに弱い)があり、''ClientAliveInterval'' の方が安全。
 +  * ClientAliveInterval 0:
 +    * 意味:サーバーからクライアントへのキープアライブパケットを送信しない(0: 無効)。
 +    * 影響:アイドル状態のSSH接続が、ファイアウォールやロードバランサ(例: AWS ELB のデフォルト60秒タイムアウト)で切断されやすい。
 +    * 問題:「Connection reset by peer」や「Broken pipe」が発生する主因。ネットワーク機器がアイドルと判断し、接続をリセット。
 +  * ClientAliveCountMax 3:
 +    * 意味:キープアライブ応答がない場合、3回試行後に接続を切断。
 +    * 影響:''ClientAliveInterval 0'' なので実質無効(パケット送信がないため)。設定変更しない限り影響なし。
 +
 +<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">nano</font> <u style="text-decoration-style:solid">/etc/ssh/sshd_config</u>
 +</pre></html></WRAP>
 +<WRAP color_result><html><pre>
 +<font color="#839496"> 107</font> <font color="#75715E">#PermitTTY yes</font>
 +<font color="#839496"> 108</font> <font color="#75715E">#PrintMotd yes</font>
 +<font color="#839496"> 109</font> <font color="#75715E">#PrintLastLog yes</font>
 +<font color="#839496"> 110</font> <span style="background-color:#333333"><font color="#75715E">#TCPKeepAlive yes</font></span><span style="background-color:#333333">                                                                                                    </span>
 +<font color="#839496"> 111</font> <font color="#F92672">TCPKeepAlive</font><font color="#FFFFFF"> no</font>
 +<font color="#839496"> 112</font> <font color="#75715E">#PermitUserEnvironment no</font>
 +<font color="#839496"> 113</font> <font color="#75715E">#Compression delayed</font>
 +<font color="#839496"> 114</font> <span style="background-color:#333333"><font color="#75715E">#ClientAliveInterval 0</font></span><span style="background-color:#333333">                                                                                               </span>
 +<font color="#839496"> 115</font> <font color="#F92672">ClientAliveInterval</font><font color="#FFFFFF"> 30</font>
 +<font color="#839496"> 116</font> <span style="background-color:#333333"><font color="#75715E">#ClientAliveCountMax 3</font></span><span style="background-color:#333333">                                                                                               </span>
 +<font color="#839496"> 117</font> <font color="#F92672">ClientAliveCountMax</font><font color="#FFFFFF"> 5</font>
 +<font color="#839496"> 118</font> <font color="#75715E">#UseDNS no</font>
 +<font color="#839496"> 119</font> <font color="#75715E">#PidFile /var/run/sshd.pid</font>
 +<font color="#839496"> 120</font> <font color="#75715E">#MaxStartups 10:30:100</font>
 +</pre></html></WRAP>
 +</WRAP>
 +  * TCPKeepAlive no: ''ClientAliveInterval'' で十分。
 +  * ClientAliveInterval 30: 30 秒ごとにキープアライブ送信。
 +  * ClientAliveCountMax 5: 回応答なし(150 秒)で切断。
 +
 +==== 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 &apos;/home/tomoyan/.ssh/id_rsa_tomoyan-2025&apos;: 
 +
 +
 +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」で切断される😢 ==== ==== SSH 接続しようとすると「Too many authentication failures」で切断される😢 ====
行 358: 行 566:
  
 === Too many authentication failures のシンプルな回避方法 === === 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&apos;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_term>
 <WRAP color_command><html><pre> <WRAP color_command><html><pre>
行 401: 行 625:
  
 === 原因まとめ === === 原因まとめ ===
-ssh-agent にロードされている秘密キーが多すぎると試行回数超えエラーにな\\ +ssh-agent は秘密鍵のパスフレーズを解除して、すぐに使えるようにしてくれているだけなので、__鍵を削除したりクリアしてしまっては意味がない__😅\\ 
-試行すると毎回接続に時間も掛かるの、<html><code>~/.ssh/config</code></html>適切定する方が素早く接続できてメリットがある😉\\+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_term>
 <WRAP color_command><html><pre> <WRAP color_command><html><pre>
行 567: 行 795:
 [[https://http2.try-and-test.net/ecdsa.html|暗号スイートの暗号強度と、公開鍵のビット数の設定、及びRSAとECDHEでサーバ負荷の比較 - Apache 2.4系でHTTP/2対応サーバを構築してみるテスト。]]\\ [[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接続が自動切断される場合の回避方法 - セキュリティ]]\\ [[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>tomoyan596/status/1461182417796931585|ということで、Windowsで作成したOpenSSHの秘密鍵が、LinuxのOpenSSHでInvalid Formatって言われちゃったら、Linux上のputtygenで一旦ppk形式の秘密鍵に変換して、それをまたputtygenでOpenSSH形式に戻してあげると生き返ります😇🤣笑 / Twitter]]\\ +[[tw>tomoyan596sp/status/1461182417796931585|ということで、Windowsで作成したOpenSSHの秘密鍵が、LinuxのOpenSSHでInvalid Formatって言われちゃったら、Linux上のputtygenで一旦ppk形式の秘密鍵に変換して、それをまたputtygenでOpenSSH形式に戻してあげると生き返ります😇🤣笑 / Twitter]]\\ 
-[[tw>tomoyan596/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/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/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]]\\ [[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.1707044697.txt.gz
  • 最終更新: 2024/02/04 20:04
  • by ともやん