在Asus Merlin固件中使用的ssh服务器为Dropbear,包括服务器和dbclient/dropbearkey等客户端工具,其中dropbearkey对应于OpenSSH的ssh-keygen工具,用于产生密钥。在Merlin固件中既可使用dbclient,也可使用ssh命令,可是没有ssh-keygen,可使用dropbearkey替代,不过参数有一些区别。html
为了在后台批量执行ssh程序,通常须要免输入密码进行登陆。通常有两种方法,即便用密钥对加入.ssh/authorized_keys进行受权和使用sshpass在命令行自动输入密码(参见:Ubuntu上使用sshpass远程脚本免密安全交互 )。密钥对方法在使用OpenSSH和Dropbear有所不一样,下面具体介绍。docker
包括使用ssh-keygen生成密钥对,上传公钥到远程服务器home/user/.ssh/目录,添加到authorized_keys文件,使用ssh自动登陆到远程服务器等步骤,具体操做过程以下:安全
由于在Asus Merlin固件中使用的ssh服务器为Dropbear,上面的过程可使用Dropbear的相关工具替代。服务器
user@RT-AC86U-xxxx:/tmp/home/root/.ssh# ls -l -a drwx------ 2 zettariv root 80 Mar 26 13:30 . drwx------ 3 zettariv root 80 Mar 26 13:11 .. -rwx------ 1 zettariv root 0 May 5 2018 authorized_keys -rw-rw-rw- 1 zettariv root 357 Mar 27 06:16 known_hosts
这是Dropbear的客户端软件,其详细使用方法以下:ssh
启动一个ssh任务的命令以下:工具
ssh -K 60 -fNgR 2200:localhost:22 user@server.remote.org
在未设置密钥以前,须要交互输入密码。this
为了连接到 dropbear 服务器,使用 dbclient 以前, 必须经过dropbearkey建立和使用public 和 private keys。以下:spa
$ dropbearkey -t ecdsa -f .ssh/id_dropbear_ecdsa | grep "^ecdsa" > .ssh/id_dropbear_ecdsa.pub Generating key, this may take a while...
若是使用rsa,以下:.net
dropbearkey -t rsa -f .ssh/id_dropbear_rsa | grep "ssh-rsa" > .ssh/id_dropbear_rsa.pub # 简化命令,须要自行提取并建立id_dropbear.pub文件 # dropbearkey -t rsa -f ~/.ssh/id_dropbear_rsa -y
显示公钥信息:命令行
nano .ssh/id_dropbear_rsa.pub
首先上传到远程服务器,以下:
scp .ssh/id_dropbear_rsa.pub supermap@myserver.remote.org:~/.ssh
把公钥信息复制/粘贴,添加到home/user/.ssh/authorized_keys文件中。
user@openbox01:~/.ssh$ nano authorized_keys
而后,再次执行上面的命令,就再也不提示输入密码了。
ssh -y -K 60 -fNgR 2200:localhost:22 user@server.remote.org -i /root/.ssh/id_dropbear_ecdsa
note
下一步,咱们将把这个命令放到启动目录中做为服务执行。参考:
让程序启动时运行还能够采用Docker和Kubernetes来调度执行。
这里的方法也适用于pc平台/树莓派上。
How To Install New Generation Entware, https://hqt.ro/how-to-install-new-generation-entware/
How to Install Debian Stretch - Arm, https://hqt.ro/how-to-install-debian-stretch-arm/
How can I install Docker in a Debian Chroot?, https://unix.stackexchange.com/questions/496860/how-can-i-install-docker-in-a-debian-chroot
Plex Media Server on AsusWRT Arm Routers, https://hqt.ro/plex-media-server-through-debian-arm/
华硕路由器官方固件开机自动运行脚本方法,http://koolshare.cn/thread-105955-1-1.html
如何将内部服务映射到外网能够访问, https://my.oschina.net/u/2306127/blog/3025654