Skip to content

Instantly share code, notes, and snippets.

@wen-long
Created May 15, 2014 16:51
Show Gist options
  • Save wen-long/0ccf771b8035ea270ae9 to your computer and use it in GitHub Desktop.
Save wen-long/0ccf771b8035ea270ae9 to your computer and use it in GitHub Desktop.

目的是为了不使用密码登录

登录(默认应该是dropbear)

先装openssh

opkg update
opkg install openssh

路由器运行ssh-keygen,文件暂时放在/tmp/id_rsa,输入一个passphrase,记住。

/tmp/id_rsa.pub的一行复制到/root/.ssh/authorized_keys

/tmp/id_rsa拷出来,putty要用它来登录

下载puttygen.exe,Conversions -> Import Key,选择刚才的id_rsa文件,输入前面的passphrase

点Save private key,把私钥保存好

修改/etc/ssh/sshd_config为如下

RSAAuthentication yes #RSA认证
PubkeyAuthentication yes #开启公钥验证
AuthorizedKeysFile /root/.ssh/authorized_keys #验证文件路径
PasswordAuthentication no #禁止密码认证
PermitEmptyPasswords yes #禁止空密码
UsePAM no #禁用PAM

让sshd自动启动 /etc/init.d/sshd enable

关闭当前ssh会话

在web页面关闭dropbear,禁用dropbear自启动,打开sshd

打开putty填IP,在Connection -> SSH -> Auth 选择前面的私钥,登录。

会询问用户名,填写。

会询问Passphrase,填写。

应该就好了。。

.ssh 目录的权限必须是0700

.ssh/authorized_keys 文件权限必须是0600

没好的话。在web页面弄回dropbear再说吧。

好了的话,可以把dropbear删了。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment