redhat 破解root密码

centos7/rhel7进入单用户方式和重置密码方式发生了较大变化,GRUB由b引导变成了ctrl+x引导。
重置密码主要有rd.break和init两种方法。


一、rd.break方法:

1、启动的时候,在启动界面,相应启动项,内核名称上按“e”;
2、进入后,找到linux16开头的地方,按“end”键到最后,输入rd.break,按ctrl+x进入;
3、进去后输入命令mount,发现根为/sysroot/,并且不能写,只有ro=readonly权限;
4、mount -o remount,rw /sysroot/,重新挂载,之后mount,发现有了r,w权限;
5、chroot /sysroot/ 改变根;
(1)echo redhat|passwd –stdin root 修改root密码为redhat,或者输入passwd,交互修改;
(2)还有就是先cp一份,然后修改/etc/shadow文件
6、touch /.autorelabel 这句是为了selinux生效
7、ctrl+d 退出
8、然后reboot
至此,密码修改完成


二、init方法:

1. 启动系统,并在GRUB2启动屏显时,按下e键进入编辑模式。
2. 在linux16/linux/linuxefi所在参数行尾添加以下内容:init=/bin/sh
3. 按Ctrl+x启动到shell。
4. 挂载文件系统为可写模式:mount –o remount,rw /
5. 运行passwd,并按提示修改root密码。
6. 如何之前系统启用了selinux,必须运行以下命令,否则将无法正常启动系统:touch /.autorelabel
7. 运行命令exec /sbin/init来正常启动,或者用命令exec /sbin/reboot重启


rd.break详细过程

1. reboot redhat系统;

2.进入启动菜单界面,选择第二个red hat enterprise linux server, with linux 0-rescue-*   ;

3.按'e'进入编辑模式, press 'e' to edit the selected item;

4.找到linux16 /vmlinuz-0-rescue-***这一行的末尾添加"rd.break",然后按Ctrl+x进入单用户模式;

5.switch_root:/# mount -o remount, rw /sysroot/

确定根目录是否只读挂载,具有可写权限;

6.切换到系统根目录下

switch_root:/# chroot /sysroot/

sh-4.2#

7.执行password -d root清除root密码

sh-4.2# passwd -d root

Removing password for user root.

passwd: Success

sh-4.2#

8.执行touch /.autorelabel

sh-4.2# touch /.autorelabel


9. Exit 退出reboot 重启

sh-4.2# exit

exit

switch_root :/# reboot



说明:
1.在紧急救援模式下看不到真实的linux系统,而且紧急模式下挂载系统一开始是r只读,需要将它改为rw可读写.

所以要先将原有的真实Linux系统mount到紧急模式下的目录

/sysroot ,才能看到真实linux系统的root和改密码;

2.切换到真实系统

chroot是把目标地址作为根目录来使用,这个目录下边是一个可以运行的系统组织。

chroot NEWROOT

run chroot with root directory set to NEWROOT
3. sysroot是指定临时根目录。

4. passwd -d

-d就是delete. This is a quick way to delete a password for an account. Available to root only.

也可以直接输入passwd,系统会提示让你输入新密码.

5.隐藏文件

linux中.开头的文件都是隐藏文件。selinux默认启动要读取一个.开头的隐藏文件.



rd.break详细过程英文版

1. Reboot the system.

2. Interrupt the boot loader count down by pressing any key.

3. Move the cursor to the entry that needs to be booted.

4. Press 'e' to edit the selected entry.

5. Move the cursor to the kernel command line ( the line that starts with linux16).

6. Append rd.break (this will break just before control is handed from the initramfs to the actual system).

(1) Remount /sysroot as read-write.

switch_root: /# mount -o remount, rw /sysroot

(2) Switch into a chroot jail, where /sysroot is treated as the root of the file system tree.

switch_root :/# chroot /sysroot

(3) Set a new root password:

sh-4.2 # passwd root

(4) Make sure that all unlabeled files (including /etc/shadow at this point) get relabeled during boot.

sh-4.2 # touch /.autorelabel








  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值