centos 遇到的 "Give root password for maintenance 。 却没办法输入密码 问题

In the event your Linux box experiences disk or file system issues you may receive a "Give root password for maintenance" prompt upon reboot. If you have your root password you can login but in the event your using 'slide' or 'sudo' for wheel access or you've just mis-placed your root password - you'll need to reset it.

To reset your root password:

1. When the GRUB loader shows during boot press the spare bar to pause boot.

2. Select your boot kernel.

3. Type 'e' to edit the default kernel line.

4. Type 'e' again on the line that starts with 'kernel'.

5. Add 'init=/bin/bash' to the end of the 'kernel' line then press enter.

6. Type 'b' to boot the modified kernel parameters.

7. Once you're at the /bin/bash prompt you will need to remount the root file system as read/write in order to edit the passwd file:

# mount -o remount,rw /

8. Change your root password:

# passwd root

9. Remount the filesystem back to read only:

# mount -o remount,ro /

10. Reboot your server using CTR-ALT-DELETE.

11. You will now be able to login with your new root password and carry out the maintenance.

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
### 回答1: CentOS 7忘记root密码的解决办法如下: 1. 重启CentOS 7系统,在grub菜单界面按下“e”键,进入编辑模式。 2. 找到以“linux16”开头的行,将其末尾的“ro”改为“rw init=/sysroot/bin/sh”。 3. 按下“Ctrl + X”或“F10”键,进入单用户模式。 4. 输入“chroot /sysroot”命令,切换到根目录。 5. 输入“passwd root”命令,重新设置root密码。 6. 输入“touch /.autorelabel”命令,更新SELinux上下文。 7. 输入“exit”命令,退出chroot环境。 8. 输入“reboot”命令,重启系统。 9. 使用新设置的root密码登录系统。 ### 回答2: 在使用CentOS 7的过程中,有些时候我们可能会忘记root密码,这是一种比较常见的问题。不过,不要担心!我们可以采取一些方法来重置密码。 如果您要重置root密码,您需要访问单用户模式,方法如下: 1.重启服务器 在计算机重新启动时,在开机过程中,您可以按下Control、Alt、Delete按键(Ctrl+Alt+Del),或者在grub画面等待3秒,然后按任意键进入grub启动菜单: 2.选择系统版本 在启动菜单里,用上下键,找到第二行,选择Ubuntu ,按e键进入命令行编辑: 在弹出的页面中,找到以"linux"开始的那一行,按e键进入编辑模式,并在其中加入 " init=/bin/bash ",然后按回车键,再按b键进行启动。这时候,CentOS就会启动到单用户模式。 3.挂载文件系统 这时候需要进行挂载文件系统,执行如下命令: # mount -o remount,rw /sysroot # chroot /sysroot 4.设置新密码 现在,我们已经进入了chroot环境下,可以使用passwd命令来为root用户设置新密码,如下所示: # passwd root 5.恢复SELinux内容 在结束更改密码操作之前,我们需要做如下SELinux恢复的操作: #touch /.autorelabel 6.重启计算机 完成密码的修改操作后,需要通过如下命令来进行重启: # reboot 通过上述方法,您就可以轻松重置CentOS 7的root密码啦! ### 回答3: 在使用CentOS 7的过程中,有时候我们会遇到忘记root账户密码的情况,这时候我们需要通过一些解决办法来恢复root账户密码。下面,我将介绍三种方法来解决这个问题。 方法一:通过单用户模式重置root密码 1.在启动CentOS 7 的时候,在 grub 菜单显示出来之前按下“e”键。 2.找到以 "linux16" 开头的那一行。 3.在那一行的结尾添加“rd.break enforcing=0 ”,然后按下 "Ctrl+x" 启动。 4.在此阶段,访问的是内核空间,它将进入一个只读(readonly)的文件系统,由于root分区此时只是只读的,我们需要将其重新挂载为可写模式: mount –o remount, rw /sysroot 5.执行chroot /sysroot 进入到 /sysroot 环境中。并使用 passwd 命令来重置root账户的密码: passwd 6.重新生成启动文件: touch /.autorelabel 7.退出chroot环境并重启系统: exit reboot 方法二:通过Live CD系统重置root密码 1.下载一个Linux Live CD系统,如Ubuntu、Redhat等 2.将Live CD系统刻录成光盘或者USB启动盘,并将其插入到CentOS 7的计算机中。 3.重启计算机,在BIOS中选择从CD或USB启动。 4.启动Live CD系统,并使用终端运行mount命令,将CentOS 7的root分区挂载到Live CD系统中: mount /dev/sdaX /mnt 5.进入root分区中的 /etc 目录,找到shadow文件,使用vim编辑器编辑此文件: vim shadow 6.找到以root为开头的那一行,将它删除或注释掉,然后保存退出。 7.使用passwd命令来设置root账户的新密码: passwd 8.卸载挂载的分区: umount /mnt 9.将Live CD光盘或者USB启动盘取出,然后重启CentOS 7系统,使用新的root密码进行登录。 方法三:通过GRUB菜单恢复密码 1.在启动GRUB菜单时,按下 "e" 键进入编辑模式。 2.找到以"linux16"开始的行,并在行尾添加 "rw init=/sysroot/bin/sh" 。 3.按下 "Ctrl + x" 继续启动系统。 4.输入 "chroot /sysroot" ,进入root分区。 5.输入 "passwd" 命令重置root账户密码。 6.重新生成启动文件: touch /.autorelabel 7.退出执行: "exit"。 8.重启系统。 通过以上三种方法中的任意一种,我们都可以成功地恢复root账户的密码,并能够顺利地使用CentOS 7系统。在实际操作过程中,请注意备份重要数据,以避免数据丢失的风险。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值