1、修改远端sshd配置

1
sudo vi /etc/ssh/sshd_config
1
2
3
4
AllowAgentForwarding yes 
AllowTcpForwarding yes 
GatewayPorts yes 
X11Forwarding yes

2、example

ssh -R

1
2
# -R [bind_address:]port:host:hostport
ssh -p 22 -o TCPKeepAlive=yes -o ServerAliveInterval=5 -o ServerAliveCountMax=10 -o StrictHostKeyChecking=no root@remote-host -R 0.0.0.0:8888:192.168.9.1:80

ssh -L

1
2
# -L [bind_address:]port:host:hostport
ssh -p 22 -N -f -C -o TCPKeepAlive=yes -o ServerAliveInterval=10 -o StrictHostKeyChecking=no root@remote-host -L 0.0.0.0:8118:127.0.0.1:8118

ssh -D

1
2
# -D [bind_address:]port
ssh -qTfnN -D port root@remote-host
1
2
3
4
5
6
7
8
-q      Quiet mode.  Causes most warning and diagnostic messages to be suppressed.

-T      Disable pseudo-terminal allocation.

-f      Requests ssh to go to background just before command execution. 后台运行,并推荐加上 -n 参数
-n      Redirects stdin from /dev/null (actually, prevents reading from stdin).  This must be used when ssh is run in the background. 
-N      Do not execute a remote command.  This is useful for just forwarding ports.
-C      Requests compression of all data.

3、ssh慢

1
sudo vi /etc/ssh/sshd_config
1
2
3
UseDNS no
# GSSAPI options
GSSAPIAuthentication no

4、autossh