差分

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

この比較画面へのリンク

両方とも前のリビジョン 前のリビジョン
次のリビジョン
前のリビジョン
linux:openssh:client [2025/02/09 13:06] – [参考文献] ともやんlinux:openssh:client [2025/03/02 06:13] (現在) – [リモートマシンから切断されて ssh がフリーズする🤪] ともやん
行 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>
  
行 344: 行 342:
 <WRAP color_term> <WRAP color_term>
 <WRAP color_command><html><pre> <WRAP color_command><html><pre>
-<font color="#FF8700"><b>$</b></font> <font color="#26A269">ssh</font> dietpi-001 hg<font color="#999999"> version</font>+<font color="#0087FF"><b>$</b></font> <font color="#26A269">ssh</font> dietpi-001 hg<font color="#999999"> version</font>
 </pre></html></WRAP> </pre></html></WRAP>
 <WRAP color_result><html><pre> <WRAP color_result><html><pre>
行 354: 行 352:
 <WRAP color_term> <WRAP color_term>
 <WRAP color_command><html><pre> <WRAP color_command><html><pre>
-<font color="#FF8700"><b>$</b></font> <font color="#26A269">ssh</font> dietpi-001 +<font color="#0087FF"><b>$</b></font> <font color="#26A269">ssh</font> dietpi-001 
-<font color="#FF8700"><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>+<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> </pre></html></WRAP>
 <WRAP color_result><html><pre> <WRAP color_result><html><pre>
行 362: 行 360:
 </pre></html></WRAP> </pre></html></WRAP>
 <WRAP color_command><html><pre> <WRAP color_command><html><pre>
-<font color="#FF8700"><b>$</b></font> <font color="#26A269">sudo</font> <font color="#26A269">systemctl</font><font color="#999999"> restart sshd</font>+<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> </pre></html></WRAP>
 </WRAP> </WRAP>
行 369: 行 367:
 <WRAP color_term> <WRAP color_term>
 <WRAP color_command><html><pre> <WRAP color_command><html><pre>
-<font color="#FF8700"><b>$</b></font> <font color="#26A269">ssh</font> dietpi-001 printenv PATH+<font color="#0087FF"><b>$</b></font> <font color="#26A269">ssh</font> dietpi-001 printenv PATH
 </pre></html></WRAP> </pre></html></WRAP>
 <WRAP color_result><html><pre> <WRAP color_result><html><pre>
行 379: 行 377:
 <WRAP color_term> <WRAP color_term>
 <WRAP color_command><html><pre> <WRAP color_command><html><pre>
-<font color="#FF8700"><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 <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="#FF8700"><b>$</b></font> <font color="#26A269">ssh</font> dietpi-001 printenv PATH+<font color="#0087FF"><b>$</b></font> <font color="#26A269">ssh</font> dietpi-001 printenv PATH
 </pre></html></WRAP> </pre></html></WRAP>
 <WRAP color_result><html><pre> <WRAP color_result><html><pre>
行 390: 行 388:
 <WRAP color_term> <WRAP color_term>
 <WRAP color_command><html><pre> <WRAP color_command><html><pre>
-<font color="#FF8700"><b>$</b></font> <font color="#26A269">ssh</font> dietpi-001 hg version+<font color="#0087FF"><b>$</b></font> <font color="#26A269">ssh</font> dietpi-001 hg version
 </pre></html></WRAP> </pre></html></WRAP>
 <WRAP color_result><html><pre> <WRAP color_result><html><pre>
行 399: 行 397:
 This is free software; see the source for copying conditions. There is NO This is free software; see the source for copying conditions. There is NO
 warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 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> </pre></html></WRAP>
 </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 &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」で切断される😢 ====
  • linux/openssh/client.1739074013.txt.gz
  • 最終更新: 2025/02/09 13:06
  • by ともやん