昨日推薦:天天學一個 Linux 命令(58):telnetlinux
ssh ( Secure Shell )命令是用於安全登陸到遠程系統的協議,它可用於在遠程服務器上記錄或執行命令。centos
ssh(SSH 客戶端)是用於登陸到遠程計算機並在遠程計算機上執行命令的程序。能夠在不安全的網絡中於兩個不受信任的主機之間提供安全的加密通訊。api
ssh [OPTIONS] [-p PORT] [USER@]HOSTNAME [COMMAND]
-4 #強制ssh協議只使用IPv4地址 -6 #強制ssh協議只使用IPv6地址 -A #啓用來自身份驗證代理的鏈接轉發 -a #禁用身份驗證代理鏈接的轉發 -B bind_interface #綁定到的地址 bind_interface在嘗試鏈接到目標主機以前 -b bind_address #使用 bind_address在本地計算機上做爲鏈接的源地址 -C #請求壓縮全部數據 -c cipher_spec #指定用於加密會話的密碼規範 -D [bind_address:] 端口 #指定本地「動態」應用程序級端口轉發 -E log_file #將調試日誌附加到 log_file 而非標準錯誤 -e escape_char #設置帶有pty的會話的轉義字符(默認值:' ~') -F 配置文件 #指定每用戶ssh的配置文件 -f #配置ssh在執行命令以前將請求轉到後臺 -g #容許遠程主機鏈接到本地轉發的端口 -i identity_file #指定從這個文件中去讀取用於公共密鑰身份驗證的標識(私有密鑰) -K #啓用基於GSSAPI的身份驗證 -k #禁用將GSSAPI憑據 -L local_socket:remote_socket #指定將與本地(客戶端)主機上給定的TCP端口或Unix套接字的鏈接轉發到遠程的給定主機和端口或Unix套接字。 -N #禁止執行遠程命令 -p port #指定SSH鏈接端口 -q #靜默模式 -s #用於請求調用遠程系統上的子系統 -T #禁用分配僞終端 -t #強制分配僞終端 -V #打印SSH版本號並退出 -v #詳細模式(輸出SSH鏈接的過程信息) -X #啓用X11轉發 -x #禁用X11轉發 -Y #啓用受信任的X11轉發 -y #指定發送日誌信息 syslog(3)系統模塊
鏈接到遠程主機安全
ssh username@remote_host #ssh 使用特定身份(私鑰)鏈接到遠程主機 ssh -i path/to/key_file username@remote_host
使用特定端口鏈接到遠程主機服務器
ssh username@remote_host -p 9999
用SSH鏈接到遠程服務器上再運行命令網絡
ssh remote_host command [root@centos7 ~]# ssh 192.168.1.199 ls The authenticity of host '192.168.1.199 (192.168.1.199)' can't be established. ECDSA key fingerprint is SHA256:mF2QLxkGH/mWhHu/NlaKOrx4nKkyVvhYV6BRPA8TdEk. ECDSA key fingerprint is MD5:a1:91:03:6b:9a:91:f6:c3:cf:19:06:32:19:b9:85:8e. Are you sure you want to continue connecting (yes/no)? yes Warning: Permanently added '192.168.1.199' (ECDSA) to the list of known hosts. root@192.168.1.199's password: anaconda-ks.cfg dos_test.txt goinception goInception-linux-amd64-v1.2.3.tar.gz httpd httpd-2.4.46 httpd-2.4.46.tar.gz mingongge.file mingongge.z01 mingongge.z02 mingongge.zip testdir test.txt
查看一下SSH遠程登陸過程的詳細信息session
[root@centos7 ~]# ssh -v 192.168.1.199 -p 22 OpenSSH_7.4p1, OpenSSL 1.0.2k-fips 26 Jan 2017 debug1: Reading configuration data /etc/ssh/ssh_config debug1: /etc/ssh/ssh_config line 58: Applying options for * debug1: Connecting to 192.168.1.199 [192.168.1.199] port 22. debug1: Connection established. debug1: permanently_set_uid: 0/0 debug1: key_load_public: No such file or directory debug1: identity file /root/.ssh/id_rsa type -1 debug1: key_load_public: No such file or directory debug1: identity file /root/.ssh/id_rsa-cert type -1 debug1: key_load_public: No such file or directory debug1: identity file /root/.ssh/id_dsa type -1 debug1: key_load_public: No such file or directory debug1: identity file /root/.ssh/id_dsa-cert type -1 debug1: key_load_public: No such file or directory debug1: identity file /root/.ssh/id_ecdsa type -1 debug1: key_load_public: No such file or directory debug1: identity file /root/.ssh/id_ecdsa-cert type -1 debug1: key_load_public: No such file or directory debug1: identity file /root/.ssh/id_ed25519 type -1 debug1: key_load_public: No such file or directory debug1: identity file /root/.ssh/id_ed25519-cert type -1 debug1: Enabling compatibility mode for protocol 2.0 debug1: Local version string SSH-2.0-OpenSSH_7.4 debug1: Remote protocol version 2.0, remote software version OpenSSH_7.4 debug1: match: OpenSSH_7.4 pat OpenSSH* compat 0x04000000 debug1: Authenticating to 192.168.1.199:22 as 'root' debug1: SSH2_MSG_KEXINIT sent debug1: SSH2_MSG_KEXINIT received debug1: kex: algorithm: curve25519-sha256 debug1: kex: host key algorithm: ecdsa-sha2-nistp256 debug1: kex: server->client cipher: chacha20-poly1305@openssh.com MAC: <implicit> compression: none debug1: kex: client->server cipher: chacha20-poly1305@openssh.com MAC: <implicit> compression: none debug1: kex: curve25519-sha256 need=64 dh_need=64 debug1: kex: curve25519-sha256 need=64 dh_need=64 debug1: expecting SSH2_MSG_KEX_ECDH_REPLY debug1: Server host key: ecdsa-sha2-nistp256 SHA256:mF2QLxkGH/mWhHu/NlaKOrx4nKkyVvhYV6BRPA8TdEk debug1: Host '192.168.1.199' is known and matches the ECDSA host key. debug1: Found key in /root/.ssh/known_hosts:1 debug1: rekey after 134217728 blocks debug1: SSH2_MSG_NEWKEYS sent debug1: expecting SSH2_MSG_NEWKEYS debug1: SSH2_MSG_NEWKEYS received debug1: rekey after 134217728 blocks debug1: SSH2_MSG_EXT_INFO received debug1: kex_input_ext_info: server-sig-algs=<rsa-sha2-256,rsa-sha2-512> debug1: SSH2_MSG_SERVICE_ACCEPT received debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mic,password debug1: Next authentication method: gssapi-keyex debug1: No valid Key exchange context debug1: Next authentication method: gssapi-with-mic debug1: Unspecified GSS failure. Minor code may provide more information No Kerberos credentials available (default cache: KEYRING:persistent:0) debug1: Unspecified GSS failure. Minor code may provide more information No Kerberos credentials available (default cache: KEYRING:persistent:0) debug1: Next authentication method: publickey debug1: Trying private key: /root/.ssh/id_rsa debug1: Trying private key: /root/.ssh/id_dsa debug1: Trying private key: /root/.ssh/id_ecdsa debug1: Trying private key: /root/.ssh/id_ed25519 debug1: Next authentication method: password root@192.168.1.199's password: debug1: Authentication succeeded (password). Authenticated to 192.168.1.199 ([192.168.1.199]:22). debug1: channel 0: new [client-session] debug1: Requesting no-more-sessions@openssh.com debug1: Entering interactive session. debug1: pledge: network debug1: client_input_global_request: rtype hostkeys-00@openssh.com want_reply 0 debug1: Sending environment. debug1: Sending env LANG = en_US.UTF-8 Last login: Sun Jan 17 14:26:28 2021 from 192.168.1.93