ssh 命令行配置项

ssh 命令有很多配置项,修改它的默认行为。

-c

-c参数指定加密算法。

$ ssh -c blowfish,3des server.example.com
# 或者
$ ssh -c blowfish -c 3des server.example.com

上面命令指定使用加密算法blowfish3des

-C

-C参数表示压缩数据传输。

$ ssh -C server.example.com

-D

-D参数指定本机的 Socks 监听端口,该端口收到的请求,都将转发到远程的 SSH 主机,又称动态端口转发,详见《端口转发》一章。

$ ssh -D 1080 server

上面命令将本机 1080 端口收到的请求,都转发到服务器server

-f

-f参数表示 SSH 连接在后台运行。

-F

-F参数指定配置文件。

$ ssh -F /usr/local/ssh/other_config

上面命令指定使用配置文件other_config

-i

-i参数用于指定私钥,意为“identity_file”,默认值为~/.ssh/id_dsa。注意,对应的公钥必须存放到服务器,详见《密钥登录》一章。

$ ssh -i my-key server.example.com

-l

-l参数指定远程登录的账户名。

$ ssh -l sally server.example.com
# 等同于
$ ssh sally@server.example.com

-L

-L参数设置本地端口转发,详见《端口转发》一章。

$ ssh  -L 9999:targetServer:80 user@remoteserver

上面命令中,所有发向本地9999端口的请求,都会经过remoteserver发往 targetServer 的 80 端口,这就相当于直接连上了 targetServer 的 80 端口。

-m

-m参数指定校验数据完整性的算法(message authentication code,简称 MAC)。

$ ssh -m hmac-sha1,hmac-md5 server.example.com

上面命令指定数据校验算法为hmac-sha1hmac-md5

-N

-N参数用于端口转发,表示建立的 SSH 只用于端口转发,不能执行远程命令,这样可以提供安全性,详见《端口转发》一章。

-o

-o参数用来指定一个配置命令。

$ ssh -o "Keyword Value"

举例来说,配置文件里面有如下内容。

User sally
Port 220

通过-o参数,可以把上面两个配置命令从命令行传入。

$ ssh -o "User sally" -o "Port 220" server.example.com

使用等号时,配置命令可以不用写在引号里面,但是等号前后不能有空格。

$ ssh -o User=sally -o Port=220 server.example.com

-p

-p参数指定 SSH 客户端连接的服务器端口。

$ ssh -p 2035 server.example.com

上面命令连接服务器的2035端口。

-q

-q参数表示安静模式(quiet),不向用户输出任何警告信息。

$ ssh –q foo.com
root’s password:

上面命令使用-q参数,只输出要求用户输入密码的提示。

-R

-R参数指定远程端口转发,详见《端口转发》一章。

$ ssh -R 9999:targetServer:902 local

上面命令需在跳板服务器执行,指定本地计算机local监听自己的 9999 端口,所有发向这个端口的请求,都会转向 targetServer 的 902 端口。

-t

-t参数在 ssh 直接运行远端命令时,提供一个互动式 Shell。

$ ssh -t server.example.com emacs

-v

-v参数显示详细信息。

$ ssh -v server.example.com

-v可以重复多次,表示信息的详细程度,比如-vv-vvv

$ ssh -vvv server.example.com
# 或者
$ ssh -v -v -v server.example.com

上面命令会输出最详细的连接信息。

-V

-V参数输出 ssh 客户端的版本。

$ ssh –V
ssh: SSH Secure Shell 3.2.3 (non-commercial version) on i686-pc-linux-gnu

上面命令输出本机 ssh 客户端版本是SSH Secure Shell 3.2.3

-X

-X参数表示打开 X 窗口转发。

$ ssh -X server.example.com

-1,-2

-1参数指定使用 SSH 1 协议。

-2参数指定使用 SSH 2 协议。

$ ssh -2 server.example.com

-4,-6

-4指定使用 IPv4 协议,这是默认值。

$ ssh -4 server.example.com

-6指定使用 IPv6 协议。

$ ssh -6 server.example.com
© 2017~ 随风逐叶 all right reserved,powered by Gitbook文章修订时间: 2021-04-25 11:46:04

results matching ""

    No results matching ""