reset password LINUX CentOS

bởi | CentOS 7, LPI

Home » LPI » reset password LINUX CentOS

reset pass Cent OS 7 khi hệ điều hành không có Grup Boot Loader Pass

+ reboot cứng server. Ở giao diện màn hình Grub boot Loader,

# Nhấn phím bất kì để ngăn cản quá trình boot mặc định
# Nhấn phím “e” => Edit

# Tìm đế dòng boot title có chữ ro và thay ro thành rw init=/sysroot/bin/sh

# Ấn Control+x để vào chế độ single mode. Chạy các lệnh dưới đây:

chroot /sysroot
passwd root (Enter and retype your new password)
touch /.autorelabel (If you do enabled Selinux)
exit
reboot

reset pass Cent OS 8 khi hệ điều hành không có Grup Boot Loader Pass

+ reboot cứng server. Ở giao diện màn hình Grub boot Loader,
# Nhấn phím bất kì để ngăn cản quá trình boot mặc định
# Nhấn phím “e” => Edit
+ Thêm vào “rd.break” ở dòng Boot của Kernel và ấn Ctrl X

+ Thực hiện các đoạn lệnh ở bên dưới theo thứ tự để thay đổi mật khẩu

mount | grep sysroot
mount -o remount,rw /sysroot/
mount | grep sysroot #thấy đã có quyền rw
chroot /sysroot
passwd
touch /.autorelabel #Nếu đang bật selinux
exit
reboot

Thiết lập Grub Boot loader password

+ Grub password: dùng để ngăn cản user vào tinh chỉnh lại boot loader, vào chế độ singer mode để đặt lại password của máy
+ vị trí của file boot loader /boot/grub2/grub.cfg:
[root@thanhdd ~]# ls /boot/grub2
+ Kiểm tra user superuser là user nào
[root@thanhdd ~]# vi /boot/grub2/grub.cfg
tới dòng 77
if [ -f ${prefix}/user.cfg ]; then
source ${prefix}/user.cfg
if [ -n "${GRUB2_PASSWORD}" ]; then
set superusers="root"
export superusers
password_pbkdf2 root ${GRUB2_PASSWORD}

+ Set pass boot loader cho supperuser
[root@thanhdd ~]# grub2-setpassword
+ Kiểm tra
[root@thanhdd ~]# cd /boot/grub2
[root@thanhdd ~]# ls -l
# sẽ thấy có thêm file user.cfg mới được tạo
[root@thanhdd ~]# cat user.cfg

Reset password bằng đĩa CD khi không có pass grub Boot loader

+ Cài đặt first boot từ CD Room, hoặc USB root. Gắn CD đĩa cài đặt hoặc USB có source cài đặt vào server. Khởi động server

+ Chọn Troubleshooting từ menu

+ Từ menu tiếp theo, chọn Rescue a CentOS system hoặc Rescue a Red Hat Enterprise Linux System

+ Chọn 1, enter để Tiếp tục

+ Gõ các lệnh sau:
sh-4.2# chroot /mnt/sysimage
bash-4.2# passwd root
Changing password for user root.
New password: **********
Retype new password: **********
passwd: all authentication tokens updated successfully.
bash-4.2# exit

+ Reboot và gỡ các kết nối source cài đặt như CD hoặc USB
sh-4.2# reboot