What should I do if I forget my centos username and password?
After forgetting your CentOS username and password, there are two ways to restore access rights: Reset the root password: Restart the server, edit the kernel command line in the GRUB menu, and add "rw init=/sysroot/bin/sh ” and press Ctrl x; mount the root file system and reset the password in single-user mode. Use rescue mode: Start the server from the CentOS installation ISO image, select rescue mode; mount the root file system, copy the chroot environment from the ISO image, reset the password, exit the chroot environment and restart the server.
How to Recover Forgotten CentOS Username and Password
Get straight to the point:
When you forget your CentOS username and password, there are two methods to restore access rights:
Method 1: Reset the root password
- Restart the server and enter GRUB menu.
- Press "e" to edit the Linux kernel command line.
- Add "rw init=/sysroot/bin/sh" at the end of the line containing "ro".
- Press Ctrl x to boot into single-user mode.
- Mount the root file system:
mount -o remount,rw /
. - Reset root password:
passwd
. - Exit the shell and restart the server.
Method 2: Using Rescue Mode
- Boot the server from the CentOS installation ISO image.
- Select "Rescue Mode".
- Mount the root file system:
mount -o remount,rw /
. - Copy the chroot environment from the ISO image to the root file system:
cp -ax /mnt/sysimage /
. - Reset root password:
passwd
. - Exit the chroot environment:
exit
. - Unmount the file system:
umount /
. - Exit rescue mode and restart the server.
Detailed steps:
Method 1:
- In the GRUB menu, usually press and hold Press the Shift key to enter.
- In the kernel command line, replace "ro" with "rw init=/sysroot/bin/sh".
- Press Ctrl x to boot into single-user mode.
- When mounting the root file system, make sure to mark it as writable (-o remount,rw).
- Enter "passwd" and enter the new password twice.
- Type "exit" to exit the shell, then press Ctrl d to restart the server.
Method 2:
- Rescue mode can usually be selected in the boot menu.
- When copying the chroot environment, make sure to replace "/mnt/sysimage" with the actual path from the ISO image.
- When exiting the chroot environment, run the "exit" command.
- When unmounting a file system, be sure to unmount the root file system (/).
The above is the detailed content of What should I do if I forget my centos username and password?. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Solution to permission issues when viewing Python version in Linux terminal When you try to view Python version in Linux terminal, enter python...

How to automatically set the permissions of unixsocket after the system restarts. Every time the system restarts, we need to execute the following command to modify the permissions of unixsocket: sudo...

Causes and solutions for errors when using PECL to install extensions in Docker environment When using Docker environment, we often encounter some headaches...

Many website developers face the problem of integrating Node.js or Python services under the LAMP architecture: the existing LAMP (Linux Apache MySQL PHP) architecture website needs...

Using python in Linux terminal...

Regarding the problem of removing the Python interpreter that comes with Linux systems, many Linux distributions will preinstall the Python interpreter when installed, and it does not use the package manager...

The problem of comparing and synchronizing BeyondCompare files: Case sensitivity failure when using Beyond...

Configure the apscheduler timing task as a service on macOS platform, if you want to configure the apscheduler timing task as a service, similar to ngin...
