<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                [TOC] ## 安裝 ``` # Ubuntu 和 Debian $ sudo apt install openssh-client # CentOS 和 Fedora $ sudo dnf install openssh-clients ``` ## 概念 ### 連接流程 1. 連接一臺陌生的服務器會有如下提示 ``` The authenticity of host 'foo.com (192.168.121.111)' can't be established. ECDSA key fingerprint is SHA256:Vybt22mVXuNuB5unE++yowF7lgA/9/2bLSiO3qmYWBY. Are you sure you want to continue connecting (yes/no)? ``` 所謂“服務器指紋”,指的是 SSH 服務器公鑰的哈希值 查看某個公鑰的指紋: ``` $ ssh-keygen -l -f /etc/ssh/ssh_host_ecdsa_key.pub 256 da:24:43:0b:2e:c1:3f:a1:84:13:92:01:52:b4:84:ff (ECDSA) ``` 2. ssh 會將本機連接過的所有服務器公鑰的指紋,都儲存在本機的`~/.ssh/known_hosts`文件中 3.第一步選擇,yes 后,公鑰指紋就會存入 `~/.ssh/know_hosts` ### 服務器密鑰變更 如果服務器的密鑰發生變更(比如重裝了 SSH 服務器),會有警告 ``` @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @ WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED! @ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY! Someone could be eavesdropping on you right now (man-in-the-middle attack)! It is also possible that the RSA host key has just been changed. The fingerprint for the RSA key sent by the remote host is 77:a5:69:81:9b:eb:40:76:7b:13:04:a9:6c:f4:9c:5d. Please contact your system administrator. Add correct host key in /home/me/.ssh/known_hosts to get rid of this message. Offending key in /home/me/.ssh/known_hosts:36 ``` 如過變成的指紋可以信任, 則可以去`~/.ssh/know_hosts` 刪除原來的指紋 或自動刪除: ``` ssh-keygen -R hostname ``` ### 加密選擇 SSH 連接的握手階段,客戶端必須跟服務端約定加密參數集(cipher suite) ``` TLS_RSA_WITH_AES_128_CBC_SHA TLS:協議 RSA:密鑰交換算法 AES:加密算法 128:加密強度 CBC:加密模式 SHA:數字簽名的 Hash 函數 ``` <details> <summary>客戶端向服務器發出的握手信息</summary> ``` Handshake protocol: ClientHello Version: TLS 1.2 Random Client time: May 22, 2030 02:43:46 GMT Random bytes: b76b0e61829557eb4c611adfd2d36eb232dc1332fe29802e321ee871 Session ID: (empty) Cipher Suites Suite: TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256” Suite: TLS_DHE_RSA_WITH_AES_128_GCM_SHA256 Suite: TLS_RSA_WITH_AES_128_GCM_SHA256 Suite: TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA Suite: TLS_DHE_RSA_WITH_AES_128_CBC_SHA Suite: TLS_RSA_WITH_AES_128_CBC_SHA Suite: TLS_RSA_WITH_3DES_EDE_CBC_SHA Suite: TLS_RSA_WITH_RC4_128_SHA Compression methods Method: null Extensions Extension: server_name Hostname: www.feistyduck.com Extension: renegotiation_info Extension: elliptic_curves Named curve: secp256r1 Named curve: secp384r1 Extension: signature_algorithms Algorithm: sha1/rsa Algorithm: sha256/rsa Algorithm: sha1/ecdsa Algorithm: sha256/ecdsa” ``` </details> <br/> >[info] Cipher Suites字段就是客戶端列出可選的加密參數集,服務器在其中選擇一個自己支持的參數集 <details> <summary>服務器選擇完畢之后,向客戶端發出回應</summary> ``` Handshake protocol: ServerHello Version: TLS 1.2 Random Server time: Mar 10, 2059 02:35:57 GMT” Random bytes: 8469b09b480c1978182ce1b59290487609f41132312ca22aacaf5012 Session ID: 4cae75c91cf5adf55f93c9fb5dd36d19903b1182029af3d527b7a42ef1c32c80 Cipher Suite: TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 Compression method: null Extensions Extension: server_name Extension: renegotiation_info” ``` </details> <br/> >[info] Cipher Suite字段就是服務器最終選定的加密參數 ## 命令 ``` -c 參數指定加密算法 如: ssh -c blowfish,3des server.example.com 或者 ssh -c blowfish -c 3des server.example.com -C 參數表示壓縮數據傳輸 如: ssh -C server.example.com -d 參數設置打印的 debug 信息級別,數值最高,輸出的內容越詳細 如: ssh –d 1 foo.com -D 參數指定本機的 Socks 監聽端口,該端口收到的請求,都將轉發到遠程的 SSH 主機 如: ssh -D 1080 server -f 參數表示 SSH 連接在后臺運行 -F 參數指定配置文件 如: ssh -F /usr/local/ssh/other_config -i 參數用于指定私鑰,默認值為~/.ssh/id_dsa,服務器必須存有對應的公鑰 如: ssh -i my-key server.example.com -L 參數設置本地端口轉發 如: ssh -L 9999:targetServer:80 user@remoteserver 表示:所有發向本地9999端口的請求,都會經過remoteserver發往 targetServer 的 80 端口 -m 參數指定校驗數據完整性的算法 -p 參數指定 SSH 客戶端連接的服務器端口 -q 參數表示安靜模式 -t 參數在 ssh 直接運行遠端命令時,提供一個互動式 Shell 如: ssh -t server.example.com vim -v 參數顯示詳細信息,可以重復多次 ``` ## 場景 ### 查看系統的公鑰 ``` ssh-keygen -l -f /etc/ssh/ssh_host_ecdsa_key.pub ``` ### 執行遠程命令(允許交互) ``` ssh username@hostname command ``` 加入 -t 參數則允許交互 ``` ssh -t username@hostname vim ``` ### 刪除變更的指紋 ``` ssh-keygen -R hostname ```
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看