Recover root password under CentOS How to Reset the Root Password in Linux

29/12/2020

 

In this tutorial we’ll see how to restore the root password for CentOS in a very simple way.

To reset your CentOS root password you’ll need to reboot or turn off your computer. Then turn on your computer and when GRUB starts press e to edit the rules and then press enter.

Scroll down and look for the line containing  ro crashkernel=auto or just ro part.

Replace ro crashkernel=auto or ro with rw init=/sysroot/bin/sh

Where:
ro = read only
rw = readable and writable

/sysroot/bin/ = OS system shell.

Make sure you edit the file properly otherwise the process will fail and you’ll need to repeat the previous steps.

Default file look:

The file must look like the screenshot below. After double checking you wrote it properly, press ctrl+x to save the changes.

Edited file look:

You’ ll get a root console from which you are able to set a new root password by running the commands below, make sure to  set a password longer than 8 characters, don’t use weak passwords which may be included in brute force dictionaries or the OS may refuse it, combine numbers, characters and symbols to increase your security.

Run the following commands:

chroot /sysroot
passwd root

Set your new password

touch /.autorelabel
exit

And then reboot

Where:

chroot /sysroot =access the OS.

passwd root  = reset root password.

touch /.autorelabel = update selinux

exit  = exit the OS
reboot

After restarting you will be able to login with the new password, now you can get back to work.

Thank you for reading this article, I hope you found this short tutorial useful. Keep following on LinuxHint for new tips and tutorials.

 

ONET IDC thành lập vào năm 2012, là công ty chuyên nghiệp tại Việt Nam trong lĩnh vực cung cấp dịch vụ Hosting, VPS, máy chủ vật lý, dịch vụ Firewall Anti DDoS, SSL… Với 10 năm xây dựng và phát triển, ứng dụng nhiều công nghệ hiện đại, ONET IDC đã giúp hàng ngàn khách hàng tin tưởng lựa chọn, mang lại sự ổn định tuyệt đối cho website của khách hàng để thúc đẩy việc kinh doanh đạt được hiệu quả và thành công.
Bài viết liên quan

[Cobbler] Tổng quan về Kickstarts Installation

Rất nhiều system administrator hiện nay ưa thích sử dụng những phương pháp tự động hóa trong vận...
30/12/2020

Chronyd dịch vụ thay thế NTPD trên Unix

Chronyd đang được đánh giá là lựa chọn tối ưu hơn NTPD để đồng bộ thời gian  trên Unix...
30/12/2020

How to Use Kickstart to Install CentOS 7

How to Use Kickstart to Install CentOS 7 You can install CentOS 7 automatically with a Kickstart file. A Kickstart file...
28/12/2020
Bài Viết

Bài Viết Mới Cập Nhật

Dịch Vụ Xây Dựng Hệ Thống Peering Với Internet Exchange (IXP)
04/04/2025

Dịch Vụ Triển Khai VPN Site-to-Site & Remote Access
04/04/2025

Dịch Vụ Thiết Lập Hệ Thống Tường Lửa (Firewall)
04/04/2025

Dịch Vụ Triển Khai Hệ Thống Ảo Hóa & Cloud
04/04/2025

Dịch Vụ Triển Khai Hệ Thống Ceph
04/04/2025