用途

通过加密连接,远程登录主机和在远程主机执行命令,也可以用于转发x11和tcp,也可用于搭建VPN。第一次连接时,会弹出远程主机公钥指纹确认信息,通过这个方式防止中间人攻击。

用法

ssh [options] [user@]hostname [command]

常用选项

-1

使用协议版本1

-2

使用协议版本2

-4

使用IPv4地址

-6

使用IPv6地址

-A

开启授权代理转发,有安全问题,一般不开启

-a

禁用authentication agent connection的转发

-b bind_address

设置连接的源地址

-C

传输时压缩数据,针对慢网速有明显的效果

-c cipher_spec

指定加密会话的算法,对于协议2版本可以指定多个且使用逗号隔开(指定多个好像没神马用><)

-D [bind_address:]port

本地动态端口转发配置,目前支持SOCKS4和SOCKS5协议

-e escape_char

给会话设置转义字符,默认是~(不知道这个选项是有什么用?)

-F configfile

指定配置文件路径,默认是/etc/ssh/ssh_config

-f

执行命令之前,ssh在后台执行

-g

允许远程主机连接本地转发端口

-I pkcs11

(Specify the PKCS#11 shared libarary ssh should use to communicate with a PKCS#11 token used for storing the user’s private RSA key.)

-i identity_file

使用私钥登录时,私钥所在的文件路径

-K

(Enables GSSAPI-based authentication and forwarding (delegation) of GSSAPI credentials to the server.)

-k

(Disables forwarding (delegation) of GSSAPI credentials to the server.)

-L [bind_address:]port:host:hostport

(Specifies that the given port on the local (client) host is to be forwarded to the given host and port on the remote side. This works by allocating a socket to listen to port on the local side, optionally bound to the specified bind_address. Whenever a connection is made to this port, the connection is forwarded over the secure channel, and a connection is made to host port hostport from the remote machine. Port forwardings can also be specified in the configuration file.)

-l login_name

设置登录远程主机用户名

-N

禁止执行远程命令,对于只是用于转发很有用

-n

(Redirects stdin from /dev/null (actually, prevents reading from stdin). This must be used when ssh is run in the background. A common trick is to use this to run X11 programs on a remote machine.)

-o option

(Can be used to give options in the format used in the configuration file. This is useful for specifying options for which there is no separate command-line flag.)

-p port

指定连接远程主机的端口,默认是22

-q

安静模式

-R [bind_address:]port:host:hostport

(Specifies that the given port on the remote (server) host is to be forwarded to the given host and port on the local side. This works by allocating a socket to listen to port on the remote side, and whenever a connection is made to this port, the connection is forwarded over the secure channel, and a connection is made to host port hostport from the local machine.)

-s

(May be used to request invocation of a subsystem on the remote system. Subsystems are a feature of the SSH2 protocol which facilitate the use of SSH as a secure transport for other applications (eg. sftp(1)). The subsystem is specified as the remote command.)

-T

(Disable pseudo-tty allocation.)

-t

(Force pseudo-tty allocation. This can be used to execute arbitrary screen-based programs on a remote machine, which can be very useful, e.g. when implementing menu services.)

-V

显示程序版本

-v

开启调试模式

-W host:port

(Requests that standard input and output on the client be forwarded to host on port over the secure channel. Implies -N, -T, ExitOnForwardFailure and ClearAllForwardings and works with Protocol version 2 only.)

-w local_tun[:remote_tun]

( Requests tunnel device forwarding with the specified tun(4) devices between the client (local_tun) and the server (remote_tun).)

-X

(Enables X11 forwarding.)

-x

(Disables X11 forwarding.)

-Y

(Enables trusted X11 forwarding. Trusted X11 forwardings are not subjected to the X11 SECURITY extension controls.)

-y

(Send log information using the syslog(3) system module. By default this information is sent to stderr.)

识别用户身份方式

1 GSSAPI-based authentication

2 host-based authentication

3 public key authentication

4 challenge-response authentication

5 password authentication

转移字符含义

~. Disconnect.

~^Z Background ssh.

~# List forwarded connections.

~& Background ssh at logout when waiting for forwarded connection / X11 sessions to terminate.

~? Display a list of escape characters.

~B Send a BREAK to the remote system (only useful for SSH protocol version 2 and if the peer supports it).

~C Open command line.

~R Request rekeying of the connection

实践

1 使用私钥登录

[root@vm ~]# ssh -p 22 -i wadeyu.pem wadeyu@192.168.2.42

2 使用账号密码登录

[root@vm ~]# ssh -p 22 wadeyu@192.168.2.42
wadeyu@192.168.2.42's password:
Last login: Tue Apr 17 11:49:11 2018 from 192.168.2.8

参考资料

【0】 man ssh

【1】实战SSH端口转发

https://www.ibm.com/developerworks/cn/linux/l-cn-sshforward/

N天学习一个linux命令之ssh的更多相关文章

  1. N天学习一个Linux命令之帮助命令:man

    前言 工作中每天都在使用常用的命令和非常用的命令,忘记了用法或者参数,都会bing一下,然后如此循环.一直没有真正的系统的深入的去了解命令的用法,我决定打破它.以前看到有人,每天学习一个linux命令 ...

  2. N天学习一个linux命令之scp

    用途 通过ssh通道,不同主机之间复制文件 用法 scp [options] [user@host:]file1 [user2@host2:]file2 常用参数 -1使用 ssh 1协议 -2使用s ...

  3. N天学习一个Linux命令之free

    用途 查看系统内存(物理/虚拟/缓存/共享)使用情况 用法 free [-b | -k | -m | -g | -h] [-o] [-s delay ] [-c count ] [-a] [-t] [ ...

  4. N天学习一个linux命令之ping

    用途 检测主机是否可到达,也就是说,目标主机是否可以联网,还可以用于检测网速.通过发送ICMP ECHO_REQUEST数据包检测. 用法 ping [options] destination 常用选 ...

  5. N天学习一个linux命令之kill

    用途 用于终止进程 用法 kill [-s signal|-p] [--] pid... kill -l [signal] 说明 1.默认发送信号15(请求终止进程,程序可以捕获,操作系统会杀死没有对 ...

  6. N天学习一个linux命令之du

    用途 统计文件或者目录占用硬盘空间大小 用法 du [OPTION] [FILE]du [OPTION] --files0-from=F 常用参数 -a, --all统计所有文件,不仅仅是目录 -b, ...

  7. 每天学习一个Linux命令-目录

    在工作中总会零零散散使用到各种Linux命令,从今天开始详细的学习一下linux常用命令,坚持每天一个命令,学习的主要参考资料为: 1.竹子-博客(https://www.cnblogs.com/pe ...

  8. N天学习一个linux命令之umask

    前言 umask不是linux命令,而是shell内置的指令,俗称用户权限掩码,用于对用户创建的文件和目录设置默认权限.默认的权限掩码是0022,也就是说新创建的文件权限是0644,新创建的目录权限是 ...

  9. N天学习一个linux命令之ip

    用途 show / manipulate routing, devices, policy routing and tunnels 用法 通用格式 ip [ OPTIONS ] OBJECT { CO ...

随机推荐

  1. thinkphp关联操作

    比如:你要求删除用户的时候,同时删除与用户有关的所有信息. 一对一:  有 (HAS_ONE)   属于 (BELONGS_TO)    一对多:  有 (HAS_MANY)  属于 (BELONG_ ...

  2. codevs2147数星星(哈希)

    2147 数星星  时间限制: 3 s  空间限制: 64000 KB  题目等级 : 钻石 Diamond   题目描述 Description 小明是一名天文爱好者,他喜欢晚上看星星.这天,他从淘 ...

  3. P2420 让我们异或吧(倍增)

    题目描述 异或是一种神奇的运算,大部分人把它总结成不进位加法. 在生活中…xor运算也很常见.比如,对于一个问题的回答,是为1,否为0.那么: (A是否是男生 )xor( B是否是男生)=A和B是否能 ...

  4. C/C++ Python的函数默认参数

    发现C/C++  Python的函数可以使用默认参数,来减少传参时候的参数个数. 但是:这样的默认参数最好是不变对象! #include <stdio.h> #include <st ...

  5. Kafka的3节点集群详细启动步骤(Zookeeper是外装)

    首先,声明,kafka集群是搭建在hadoop1.hadoop2和hadoop3机器上. kafka_2.10-0.8.1.1.tgz的1或3节点集群的下载.安装和配置(图文详细教程)绝对干货 如下分 ...

  6. 网上流行的学生选课相关的50个常用sql语句

    学生表 Student(S#,Sname,Sage,Ssex) 教师表 Teacher(T#,Tname) 课程表 Course(C#,Cname,T#) 学生成绩表 SC(S#,C#,score) ...

  7. 【java并发容器】并发容器之CopyOnWriteArrayList

    原文链接: http://ifeve.com/java-copy-on-write/ Copy-On-Write简称COW,是一种用于程序设计中的优化策略.其基本思路是,从一开始大家都在共享同一个内容 ...

  8. Android RecyclerView notifyDataSetChanged不起作用

    一般listview设置完data后调用notifyDataSetChanged便可刷新布局界面,然而recycleview调用这个方法却没有任何反应.对于很多不熟悉recycleview的话很容易躺 ...

  9. hibernate 级联删除报更新失败的问题(org.hibernate.exception.GenericJDBCException: Could not execute JDBC batch update)

    首先hibernate级联删除的前提是,首先需要在映射文件中配置,配置多表之间的关联关系: 下面以部门表(Dept)和员工表(Emp)为例: 1.在Emp.hbm.xml映射文件中配置many-to- ...

  10. Angular——流程控制指令

    基本介绍 (1)ng-repeat,类似于for循环,对数组进行遍历 (2)ng-switch on,ng-switch-when,类似于switch,case 基本使用 ng-repeat < ...