ssh-remote-port-forwarding

1、ssh免密码登录(A登录到B)
  1.1、在A上执行并在~/.ssh下生成id_rsa和id_rsa.pub两个文件

ssh-keygen -t rsa -P ''

  1.2、拷贝id_rsa.pub到B的~/.ssh/authorized_keys文件中

scp ~/.ssh/id_rsa.pub tato@192.168.1.100:~/.ssh/authorized_keys

  1.3、ssh公钥生效需满足至少下面两个条件
    1)、.ssh目录的权限必须是700
    2)、authorized_keys文件权限必须是600
  1.4、在A上免密登录到B

ssh tato@192.168.1.100

2、ssh远程端口反转

ssh -R <local port>:<remote host>:<remote port> <SSH hostname>

  2.3、A上执行

ssh -i ~/.ssh/id_rsa.pub -o StrictHostKeyChecking=no -NfR 2026:127.0.0.1:22 tato@192.168.1.113

  2.4、B上执行

ssh -p 2026 root@127.0.0.1
原文地址:https://www.cnblogs.com/qintangtao/p/7000282.html