70 lines
2.5 KiB
Markdown
70 lines
2.5 KiB
Markdown
## OpenWrt的ssh无法登陆问题Permission denied, please try again.解决
|
||
|
||
## 一、情况描述:
|
||
|
||
我根据B站的博主提供的[教程](https://www.bilibili.com/video/BV1114y1X7TA/?spm_id_from=333.337.search-card.all.click&vd_source=926e07668711afad2745ecb7dc75a3d1)对红米AC2100路由器进行刷机。最开始刷的Openwrt是可以连接ssh的,后面的升级改进版就无法进入ssh了,具体的错误如下。``
|
||
|
||
```shell
|
||
#采用windows的powershell登陆
|
||
ssh root@192.168.30.1
|
||
root@192.168.30.1's password:
|
||
Permission denied, please try again.
|
||
|
||
# openwrt后台log
|
||
Sat Feb 10 01:15:01 2024 authpriv.info dropbear[11072]: Child connection from 192.168.30.247:62748
|
||
Sat Feb 10 01:15:01 2024 authpriv.warn dropbear[11072]: User 'root' has invalid shell, rejected
|
||
```
|
||
|
||
上述问题在于,我输入的密码是对的但是依旧无法登陆。查看`etc/passwd`发现密码是正确的。
|
||
|
||
```shell
|
||
root:x:0:0:root:/root:/bin/bash
|
||
daemon:*:1:1:daemon:/var:/bin/false
|
||
ftp:*:55:55:ftp:/home/ftp:/bin/false
|
||
network:*:101:101:network:/var:/bin/false
|
||
```
|
||
|
||
为了解决上述的问题,我调查了好几种原因和解决方案。我遇到的问题是系统目录的`etc\shells`文件中没有`/bin/bash`,导致的无法登陆。那么其他的原因有:
|
||
|
||
```shell
|
||
# 1. etc/passwd换行问题导致 https://blog.csdn.net/railzen/article/details/132835654
|
||
# 2. /bin/bash没有加入 https://blog.csdn.net/weixin_33849215/article/details/93449289
|
||
```
|
||
|
||
## 二、解决方案
|
||
|
||
通过OpenWrt的web界面查看文件管理,下载`etc\shells`文件。然后发现内容如下:
|
||
|
||
```shell
|
||
/bin/ash
|
||
/usr/bin/zsh
|
||
```
|
||
|
||
那么我们加入`/bin/bash`到`etc\shells`文件中,并通过Web管理界面的文件管理功能上传到OpenWrt上,然后重启路由器。
|
||
|
||
```
|
||
/bin/bash
|
||
/bin/ash
|
||
/usr/bin/zsh
|
||
```
|
||
|
||
在Powershell中输入`ssh root@192.168.30.1`,成功进入ssh。
|
||
|
||
```shell
|
||
C:\Users\admin>ssh root@192.168.30.1 -p 22
|
||
_____
|
||
_____________________________ __________ /_
|
||
_ __ \__ __ \ _ \_ __ \_ | /| / /_ ___/ __/
|
||
/ /_/ /_ /_/ / __/ / / /_ |/ |/ /_ / / /_
|
||
\____/_ .___/\___//_/ /_/____/|__/ /_/ \__/
|
||
/_/
|
||
_________________________________________
|
||
|
||
OpenWrt 07.12.2023 by Kiddin'
|
||
_________________________________________
|
||
|
||
系统负载: 0.94 0.39 0.14 运行时间: 1 min
|
||
内存已用: 46 % of 116MB IP 地址: 192.168.30.1 192.168.1.12
|
||
```
|
||
|