共计 5559 个字符,预计需要花费 14 分钟才能阅读完成。
昨日举荐: 每天学一个 Linux 命令(58):telnet
命令简介
ssh (Secure Shell) 命令是用于平安登录到近程零碎的协定,它可用于在近程服务器上记录或执行命令。
ssh(SSH 客户端)是用于登录到近程计算机并在近程计算机上执行命令的程序。能够在不平安的网络中于两个不受信赖的主机之间提供平安的加密通信。
语法格局
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 近程登录过程的详细信息
[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 |
每天学一个 Linux 命令(55):id
每天学一个 Linux 命令(56):su/sudo
每天学一个 Linux 命令(57):cal
正文完