35

树莓派重置密码

 4 years ago
source link: https://www.tuicool.com/articles/mAv2U3Y
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

昨天折腾树莓派时感觉自己又上升了一个层次,于是设置密码时用了一个酷炫的新密码。今天起床后进系统发现傻逼了,完全想不起新密码是什么:sob::sob:好在硬件就在身边,重置一下密码就可以了。

以下是重置树莓派系统密码的步骤。

  1. 取出sd卡,放入usb读卡器中,连接到其它电脑;
  2. 在其它电脑中打开sd卡的 cmdline.txt 文件,在行尾加上 init=/bin/sh 。修改好后的 cmdline.txt 文件内容大致是这样:
    console=serial0,115200 console=tty1 root=/dev/mmcblk0p7 rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait quiet splash plymouth.ignore-serial-consoles init=/bin/sh
  3. 把sd卡重新放入树莓派,通电开机。
  4. 出现树莓派的logo后很快进入命令行界面,可以看到行首是”#”,说明已经获取了root权限;
  5. 为了避免树莓派进入只读模式,重新挂载sd卡: mount -rw -o remount /
  6. 重置pi用户的密码: passwd pi ,两次输入新密码;
  7. 让系统继续加载进入默认环境: exec /sbin/init
  8. 系统加载完后,登录用root权限修改 /boot/cmdline.txt 文件,将 init=/bin/sh 移除。

其原理是:系统以root权限启动, init=/bin/sh 指令让系统启动时直接进入root用户的shell,进而可以做任何想做的事情。

参考

  1. http://mapledyne.com/ideas/2015/8/4/reset-lost-admin-password-for-raspberry-pi

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK