利用autossh建立端口映射

安装autossh:

yum install autossh #centos

apt-get install autossh #ubuntu 

 

使用ssh建立tunnel,在shell中执行:

ssh -NfR 1234:localhost:22 user@masterIp

##隧道开启:将node的22端口映射到master的1234端口,此时在master上ssh localhost -p 1234就能连接到node

 

 

使用autossh建立永久tunnel

autossh -M 5678 -NfR 1234:localhost:22 user@masterIp

## 5678为监控端口,此方法需要输入密码

 

 

使用autossh建立永久tunnel 无需密码

1.在master主机上生产公钥和私钥

$ ssh-keygen ...(一直按Enter,最后在~/.ssh/下生成密钥) $ ls ~/.ssh/ id_rsa id_rsa.pub known_hosts

 

2.复制B主机上生成的id_rsa.pub公钥到外网A主机上,并将内容加入到~/.ssh/authorized_keys中

$ cat id_rsa.pub >> ~/.ssh/authorized_keys

 

 

3. 然后执行

autossh -M 5678 -NfR 1234:localhost:22 user@masterIp

## 若是没有吧pub文件移动到authorized_keys中 需要在命令后加上-i参数 后跟pub 的文件路径

autossh -M 5678 -NfR 1234:localhost:22 user@masterIp -i id_rsa.pub

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值