两台openwrt 间的免登陆ssh

参考文档:

http://www.360doc.com/content/13/1013/21/3884271_321222563.shtml

http://blog.csdn.net/u011007991/article/details/54378998

http://www.xuebuyuan.com/1624349.html

ssh过程:

1、首先,在client端生成一对密钥:

root@Router:/etc/dropbear# dropbearkey -t rsa -f /etc/dropbear/my_secret_key

这样会生成一个my_secret_key的私钥放在client端,并且会显示一大段字段,可以手工取其中的ssh-rsa一句另存为一个叫authorized_keys文件,也可以用下面这句生成:

dropbearkey -t rsa -f /etc/dropbear/my_secret_key | grep ssh-rsa > authorized_keys

2、把authorized_key放到远端路由器的/etc/dropbear/authorized_keys

3、在本地端建一个自动脚本,用来检测ssh是否断开并自动重连,例如叫authssh.sh:

#!/bin/sh
if netstat -tln | grep ":1234"
then
  echo "sshtunnel is working"
else
  ssh -fN [email protected] -p 22 -i /etc/dropbear/my_secret_key -L 0.0.0.0:1234:192.168.1.1:1194 -K 5
fi

4、使用定时任务每5分钟执行脚本,为什么放在luci-uploads目录,因为这个目录会由openwrt的备份一并备份起来,刷机也可以再找回来啊。

crontab -e

*/5 * * * * /etc/luci-uploads/authssh.sh

5、至于openvpn属于另一个研究内容,本文不作记录,只需知道openvpn client配置只需写成本机的地址:

remote 127.0.0.1:1234

以上过程纯属自娱自乐,如有雷同实属巧合。

猜你喜欢

转载自blog.csdn.net/d9394952/article/details/87867939
今日推荐