一、生成密钥
toor@SurfaceBook:~$ ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/home/toor/.ssh/id_rsa):
Created directory '/home/toor/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/toor/.ssh/id_rsa.
Your public key has been saved in /home/toor/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:U2ZM6mqTrxl0e/JWVygB9fw6RXHZBHcinGM7wegMmws
toor@SurfaceBook
The key's randomart image is:
+---[RSA 2048]----+
| o*o.o+B|
| .+. O+ +=|
| .*=. =o..|
| E.o+o + .o.|
| ..S. o .o|
| . +.o . .o |
| * o .. .o |
| . = +. . |
| o.... |
+----[SHA256]-----+
toor@SurfaceBook:~$ ll .ssh
总用量 4
drwx------ 0 toor toor 512 11月 30 20:37 ./
drwxr-xr-x 0 toor toor 512 11月 30 20:37 ../
-rw------- 1 toor toor 1679 11月 30 20:37 id_rsa
-rw-r--r-- 1 toor toor 398 11月 30 20:37 id_rsa.pub
二、上传公钥到OpenWrt
ssh-copy-id root@tw -p1022
此时公钥在路由器中的位置: /root/.ssh/authorized_keys将公钥拷贝到 dropbear 目录下,并赋予争取的权限
cp /root/.ssh/authorized_keys /etc/dropbear/
chmod 700 /etc/dropbear
chmod 600 /etc/dropbear/authorized_keys
使用私钥登录
ssh -i ~/.ssh/id_rsa root@tw -p 1022
不出意外的话,登录成功
三、更方便的登录方法
在客户端进行如下修改:
vim .ssh/config
# 添加如下配置
Host gee
HostName tw
Port 1022
IdentityFile ~/.ssh/id_rsa
User root
然后就可以使用 Host 指定的名称登陆了。
toor@SurfaceBook:~$ ssh gee
BusyBox v1.25.1 () built-in shell (ash)
***********************************************************
__ __ _ _ ____ _ TM
/ / / / (_) _ __ (_) / __/ (_)
/ /_/ / / / | | /| / / / / / /_ / /
/ __ / / / | |/ |/ / / / / __/ / /
/_/ /_/ /_/ |__/|__/ /_/ /_/ /_/
http://www.hiwifi.com/
***********************************************************
root@Hiwifi:~#
享受吧
文章来源:https://stray.love/wen-ti-jie-jue-fang-an/shi-yong-gong-yao-deng-lu-openwrt