Ubuntu20.04/22.04忘记root密码

启动时按下 SHIFT + ESC 键,进入 GRUB 引导加载器页面

接着会出现几种模式,分别是高级模式、内存测试...

选择第一个选项Advanced options for Ubuntu(进入高级模式),选择Ubuntun with Linux 5.15.0-52-generic (注意,不是带recovery mode字样的项) 并按 e 键进入编辑模式

在以 linux 开头的一行末尾,删除字符串 $vt_handoff 并添加字符串 ro quiet splash systemd.unit=rescue.target 
注:ro是自带项,后面的quiet splash systemd.unit=rescue.target 是要手动输入的

做完修改后,按 Ctrl + X 或 F10 在救援模式下启动

进到(or press Control-D to continue):   界面是按回车即可
sudo passwd        # root密码必须是8位及以上且必须是数字、大小写字母、特殊字符的组合

修改完后执行systemctl reboot进行重启

允许root远程登录

sudo vim /etc/ssh/sshd_config
PermitRootLogin yes

sudo systemctl restart sshd

.
.
.
.
游走在各发行版间老司机QQ群:905201396
不要嫌啰嗦的新手QQ群:756805267
Debian适应QQ群:912567610

posted @ 2022-12-28 06:35  Linux大魔王  阅读(2746)  评论(0编辑  收藏  举报