ssh 命令行配置项
# ssh 命令行配置项
ssh 命令有很多配置项,修改它的默认行为。
-c
-c
参数指定加密算法。
$ ssh -c blowfish,3des server.example.com
# 或者
$ ssh -c blowfish -c 3des server.example.com
2
3
上面命令指定使用加密算法blowfish
或3des
。
-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
2
3
-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-sha1
或hmac-md5
。
-N
-N
参数用于端口转发,表示建立的 SSH 只用于端口转发,不能执行远程命令,这样可以提供安全性,详见《端口转发》一章。
-o
-o
参数用来指定一个配置命令。
$ ssh -o "Keyword Value"
举例来说,配置文件里面有如下内容。
User sally
Port 220
2
通过-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:
2
上面命令使用-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
2
3
上面命令会输出最详细的连接信息。
-V
-V
参数输出 ssh 客户端的版本。
$ ssh –V
ssh: SSH Secure Shell 3.2.3 (non-commercial version) on i686-pc-linux-gnu
2
上面命令输出本机 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