树莓派 忘记密码的解决方法

来源:互联网 发布:飞凌单片机开发工具 编辑:程序博客网 时间:2024/06/09 17:48

忘记树莓派密码怎么办?
原文连接:http://www.raspberrypi-spy.co.uk/2014/08/how-to-reset-a-forgotten-raspberry-pi-password/
大致过程是这样的:
1、首先将sd卡从树莓派取出,
2、在另一台电脑上,修改初始化进程为bin目录下的sh;
3、然后插入树莓派启动起来,启动后会停留在命令行,在此通过passwd加你的用户名来设置密码(即使root也可以在此修改,这里之前是否初始化过root密码不太确定)
4、树莓派关机,取出sd卡,插入另一台电脑,恢复启动文件,修改密码过程完成

详细步骤看翻译吧

翻译如下:
Step 1 – Grab The SD Card
步骤1-取出sd卡
Power down the Pi and remove the SD card. Insert it into your PC.
将树莓派关机,移除sd卡,插入到你的电脑
Step 2 – Edit cmdline.txt
步骤2-编辑cmdline.txt
The boot partition should be visible and contain a file named “cmdline.txt”. Edit this file in a text editor and add the following to the end of the existing text :
启动部分是可见的,并包含一个名为“cmdline.txt”的文件。在编辑器中编辑这个文本,并将下文插入到已有文本的最后
init=/bin/sh
If the original content was :
如果原文是这样的:
dwc_otg.lpm_enable=0 console=ttyAMA0,115200 kgdboc=ttyAMA0,115200 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline rootwait
it should now look like :
那么编辑后应该是这样的:
dwc_otg.lpm_enable=0 console=ttyAMA0,115200 kgdboc=ttyAMA0,115200 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline rootwait init=/bin/sh
Make sure it is all one line! Save the text file and eject the SD card from the PC.
确保所有内容在同一行。保存文本内容,从pi出取出sd卡
Step 3 – Reset the Password
步骤3-重设密码
Insert the card into a Pi that is connected to a monitor and keyboard. Power up the Pi. There may be a delay but you should be presented with a flashing cursor.
 将sd卡插入树莓派(我们在这里需要连上显示器和键盘)。将树莓派开机,估计在显示闪动的光标前需要等一会。
At the prompt type the following command :
在标识符后,输入以下命令:
passwd pi
You will then be prompted for a new password. Enter it carefully and press the [Return] key. It will now ask you to retype the password.
你会被提示输入一个新的密码,请仔细输入后并敲下回车键。系统会提示你再次确认输入密码
The password has been changed.
这样密码就修改完成了
Now type the following commands :
现在输入以下命令去同步并执行初始化程序
sync
exec /sbin/init
The Pi will continue to boot and return you to the normal command line prompt.
树莓派会继续启动
Shutdown the Pi and power it off.
关掉树莓派并且断电
sudo halt
Step 4 – Edit cmdline.txt
第四步-编辑cmdline.txt文本
Using the PC edit the “cmdline.txt” file again and remove the “init=/bin/sh” text you added in Step 2.
用电脑再次编辑这个文本:把我们在第二步加入的最后数据删除
You can now return the SD card to your Pi, reboot and use the new password.
现在你可以插入sd卡到你的树莓派啦,再次启动就可以使用新的密码啦。

提示Authentication token manipulation error错误的原因是:
1、分区没有空间导致。
2、/etc/passwd 和/etc/shadow不同步
但是这次上面两条却行不通,通过df查看根分区还有40%剩余。

1、尝试修改密码,出现错误

passwd

Changing password for user root.
New UNIX password:
BAD PASSWORD: it is WAY too short
Retype new UNIX password:
passwd: Authentication token manipulation error
2、同步/etc/passwd 和/etc/shadow出错
#pwconv
pwconv: can’t lock passwd file
3、看权限没有异常,也没有进程锁定该文件

ll /etc/passwd

-rwxr–r– 1 root root 2752 Dec 31 17:29 /etc/passwd

fuser -u /etc/passwd

lsof |grep passwd

4、cp lock文件出错,提示空间不足

cp /tmp/.pwd.lock /etc/

cp: cannot create regular file `/etc/.pwd.lock’: No space left on device
5、上面的错误惊醒了我,查看确实是inode满了,删除无用的文件

df -i

Filesystem Inodes IUsed IFree IUse% Mounted on
/dev/sda5 2562240 2562240 0 100% /
/dev/sda1 50200 47 50153 1% /boot
/dev/sda2 51300000 12 51299988 1% /data/cache1
/dev/sdb1 51300000 7080311 44219689 14% /data/cache2
/dev/sdb2 9863168 11 9863157 1% /data/proclog
none 215907 1 215906 1% /dev/shm
/dev/sda3 3842720 305795 3536925 8% /usr
/dev/sda7 3162112 7893 3154219 1% /var
6、再次修改密码仍然出错,于是尝试修改/etc/passwd也出现错误

chmod 777 /etc/passwd

chmod: changing permissions of `/etc/passwd’: Operation not permitted
7、执行chattr

chattr -i /etc/passwd

lsattr -v /etc/passwd

2095582053 ————- /etc/passwd

chattr -i /etc/shadow

8、同步文件
pwconv
9、成功修改密码
passwd
Changing password for user root.
New UNIX password:
BAD PASSWORD: it is WAY too short
Retype new UNIX password:
passwd: all authentication tokens updated successfully.

附:pwconv
功能说明:开启用户的投影密码。
语法:pwconv
补充说明:Linux系统里的用户和群组密码,分别存放在名称为passwd和group的文 件中,这两个文件位于/etc目录下。因系统运作所需,任何人都得以读取它们,造成安全上的破绽。投影密码将文件内的密码改存在/etc目录下的 shadow和gshadow文件内,只允许系统管理者读取,同时把原密码置换为”x”字符,有效的强化了系统的安全性。
pwconv:开启用户的shadow口令.
一般来用pwconv来同步口令,下面来说一下,它的工作流程:
pwconv依赖于passwd中的密码区’x’来同步/etc/passwd与/etc/shadow这两个文件;以/etc/passwd为主来控制/etc/shadow中的各项:
A:若/etc/shadow不存在,则pwconv将用/etc/passwd来建立
B:若/etc/shadow已存在,则:
1.若条目在passwd中已存在,而不在shadow中,则在shadow中添加相关条目
2.若条目在shadow中已存在,而不在passwd中,则从shadow中删除相关条目

Linux下出现Read-only file system的解决办法

正常运行中的网站,忽然间出现session目录不可写,连接服务器一看,任何关于写硬盘的命令都不能用,提示Read-only file system,使用一条命令即可搞定此问题:
1. mount -o remount rw /
本文地址:http://www.92csz.com/21/1247.html
如非注明则为本站原创文章,欢迎转载。转载请注明转载自:moon’s blog

0 0
原创粉丝点击