昨日举荐:每天学一个 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 lsThe 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)? yesWarning: Permanently added '192.168.1.199' (ECDSA) to the list of known hosts.root@192.168.1.199's password: anaconda-ks.cfgdos_test.txtgoinceptiongoInception-linux-amd64-v1.2.3.tar.gzhttpdhttpd-2.4.46httpd-2.4.46.tar.gzmingongge.filemingongge.z01mingongge.z02mingongge.ziptestdirtest.txt

查看一下SSH近程登录过程的详细信息

[root@centos7 ~]# ssh -v 192.168.1.199 -p 22OpenSSH_7.4p1, OpenSSL 1.0.2k-fips  26 Jan 2017debug1: Reading configuration data /etc/ssh/ssh_configdebug1: /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/0debug1: key_load_public: No such file or directorydebug1: identity file /root/.ssh/id_rsa type -1debug1: key_load_public: No such file or directorydebug1: identity file /root/.ssh/id_rsa-cert type -1debug1: key_load_public: No such file or directorydebug1: identity file /root/.ssh/id_dsa type -1debug1: key_load_public: No such file or directorydebug1: identity file /root/.ssh/id_dsa-cert type -1debug1: key_load_public: No such file or directorydebug1: identity file /root/.ssh/id_ecdsa type -1debug1: key_load_public: No such file or directorydebug1: identity file /root/.ssh/id_ecdsa-cert type -1debug1: key_load_public: No such file or directorydebug1: identity file /root/.ssh/id_ed25519 type -1debug1: key_load_public: No such file or directorydebug1: identity file /root/.ssh/id_ed25519-cert type -1debug1: Enabling compatibility mode for protocol 2.0debug1: Local version string SSH-2.0-OpenSSH_7.4debug1: Remote protocol version 2.0, remote software version OpenSSH_7.4debug1: match: OpenSSH_7.4 pat OpenSSH* compat 0x04000000debug1: Authenticating to 192.168.1.199:22 as 'root'debug1: SSH2_MSG_KEXINIT sentdebug1: SSH2_MSG_KEXINIT receiveddebug1: kex: algorithm: curve25519-sha256debug1: kex: host key algorithm: ecdsa-sha2-nistp256debug1: kex: server->client cipher: chacha20-poly1305@openssh.com MAC: <implicit> compression: nonedebug1: kex: client->server cipher: chacha20-poly1305@openssh.com MAC: <implicit> compression: nonedebug1: kex: curve25519-sha256 need=64 dh_need=64debug1: kex: curve25519-sha256 need=64 dh_need=64debug1: expecting SSH2_MSG_KEX_ECDH_REPLYdebug1: Server host key: ecdsa-sha2-nistp256 SHA256:mF2QLxkGH/mWhHu/NlaKOrx4nKkyVvhYV6BRPA8TdEkdebug1: Host '192.168.1.199' is known and matches the ECDSA host key.debug1: Found key in /root/.ssh/known_hosts:1debug1: rekey after 134217728 blocksdebug1: SSH2_MSG_NEWKEYS sentdebug1: expecting SSH2_MSG_NEWKEYSdebug1: SSH2_MSG_NEWKEYS receiveddebug1: rekey after 134217728 blocksdebug1: SSH2_MSG_EXT_INFO receiveddebug1: kex_input_ext_info: server-sig-algs=<rsa-sha2-256,rsa-sha2-512>debug1: SSH2_MSG_SERVICE_ACCEPT receiveddebug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mic,passworddebug1: Next authentication method: gssapi-keyexdebug1: No valid Key exchange contextdebug1: Next authentication method: gssapi-with-micdebug1: Unspecified GSS failure.  Minor code may provide more informationNo Kerberos credentials available (default cache: KEYRING:persistent:0)debug1: Unspecified GSS failure.  Minor code may provide more informationNo Kerberos credentials available (default cache: KEYRING:persistent:0)debug1: Next authentication method: publickeydebug1: Trying private key: /root/.ssh/id_rsadebug1: Trying private key: /root/.ssh/id_dsadebug1: Trying private key: /root/.ssh/id_ecdsadebug1: Trying private key: /root/.ssh/id_ed25519debug1: Next authentication method: passwordroot@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.comdebug1: Entering interactive session.debug1: pledge: networkdebug1: client_input_global_request: rtype hostkeys-00@openssh.com want_reply 0debug1: Sending environment.debug1: Sending env LANG = en_US.UTF-8Last login: Sun Jan 17 14:26:28 2021 from 192.168.1.93

每天学一个 Linux 命令(55):id

每天学一个 Linux 命令(56):su/sudo

每天学一个 Linux 命令(57):cal