端口转发
本地转发:把远端端口映射到本机。
ssh -N -L 8080:127.0.0.1:80 user@host
远程转发:把本机端口暴露到远端(需要 GatewayPorts 配合)。
ssh -N -R 9000:127.0.0.1:3000 user@host
动态转发:起一个 socks5。
ssh -N -D 1080 user@host
保持连接
客户端加这两行,避免闲置断线:
# ~/.ssh/config
Host *
ServerAliveInterval 30
ServerAliveCountMax 3
跳板机
ssh -J jump@bastion target@10.0.0.5
或者写进 config:
Host target
HostName 10.0.0.5
User target
ProxyJump bastion
复制文件
免去记 scp 的参数,直接走 ssh 通道:
tar czf - ./dir | ssh user@host 'tar xzf - -C /srv'
反过来也行,只是把两边调换一下。