每天学一个 Linux 命令(59):ssh

隆儿
• 阅读 3841

每天学一个 Linux 命令(59):ssh

昨日推荐:每天学一个 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

点赞
收藏
评论区
推荐文章
blmius blmius
3年前
MySQL:[Err] 1292 - Incorrect datetime value: ‘0000-00-00 00:00:00‘ for column ‘CREATE_TIME‘ at row 1
文章目录问题用navicat导入数据时,报错:原因这是因为当前的MySQL不支持datetime为0的情况。解决修改sql\mode:sql\mode:SQLMode定义了MySQL应支持的SQL语法、数据校验等,这样可以更容易地在不同的环境中使用MySQL。全局s
皕杰报表之UUID
​在我们用皕杰报表工具设计填报报表时,如何在新增行里自动增加id呢?能新增整数排序id吗?目前可以在新增行里自动增加id,但只能用uuid函数增加UUID编码,不能新增整数排序id。uuid函数说明:获取一个UUID,可以在填报表中用来创建数据ID语法:uuid()或uuid(sep)参数说明:sep布尔值,生成的uuid中是否包含分隔符'',缺省为
Wesley13 Wesley13
3年前
FLV文件格式
1.        FLV文件对齐方式FLV文件以大端对齐方式存放多字节整型。如存放数字无符号16位的数字300(0x012C),那么在FLV文件中存放的顺序是:|0x01|0x2C|。如果是无符号32位数字300(0x0000012C),那么在FLV文件中的存放顺序是:|0x00|0x00|0x00|0x01|0x2C。2.  
Wesley13 Wesley13
3年前
mysql设置时区
mysql设置时区mysql\_query("SETtime\_zone'8:00'")ordie('时区设置失败,请联系管理员!');中国在东8区所以加8方法二:selectcount(user\_id)asdevice,CONVERT\_TZ(FROM\_UNIXTIME(reg\_time),'08:00','0
Wesley13 Wesley13
3年前
PHP创建多级树型结构
<!lang:php<?php$areaarray(array('id'1,'pid'0,'name''中国'),array('id'5,'pid'0,'name''美国'),array('id'2,'pid'1,'name''吉林'),array('id'4,'pid'2,'n
Wesley13 Wesley13
3年前
Java日期时间API系列36
  十二时辰,古代劳动人民把一昼夜划分成十二个时段,每一个时段叫一个时辰。二十四小时和十二时辰对照表:时辰时间24时制子时深夜11:00凌晨01:0023:0001:00丑时上午01:00上午03:0001:0003:00寅时上午03:00上午0
Wesley13 Wesley13
3年前
00:Java简单了解
浅谈Java之概述Java是SUN(StanfordUniversityNetwork),斯坦福大学网络公司)1995年推出的一门高级编程语言。Java是一种面向Internet的编程语言。随着Java技术在web方面的不断成熟,已经成为Web应用程序的首选开发语言。Java是简单易学,完全面向对象,安全可靠,与平台无关的编程语言。
Stella981 Stella981
3年前
Django中Admin中的一些参数配置
设置在列表中显示的字段,id为django模型默认的主键list_display('id','name','sex','profession','email','qq','phone','status','create_time')设置在列表可编辑字段list_editable
Wesley13 Wesley13
3年前
MySQL部分从库上面因为大量的临时表tmp_table造成慢查询
背景描述Time:20190124T00:08:14.70572408:00User@Host:@Id:Schema:sentrymetaLast_errno:0Killed:0Query_time:0.315758Lock_
Python进阶者 Python进阶者
1年前
Excel中这日期老是出来00:00:00,怎么用Pandas把这个去除
大家好,我是皮皮。一、前言前几天在Python白银交流群【上海新年人】问了一个Pandas数据筛选的问题。问题如下:这日期老是出来00:00:00,怎么把这个去除。二、实现过程后来【论草莓如何成为冻干莓】给了一个思路和代码如下:pd.toexcel之前把这
美凌格栋栋酱 美凌格栋栋酱
5个月前
Oracle 分组与拼接字符串同时使用
SELECTT.,ROWNUMIDFROM(SELECTT.EMPLID,T.NAME,T.BU,T.REALDEPART,T.FORMATDATE,SUM(T.S0)S0,MAX(UPDATETIME)CREATETIME,LISTAGG(TOCHAR(