Home  >  Article  >  Operation and Maintenance  >  What should I do if I forget my centos username and password?

What should I do if I forget my centos username and password?

下次还敢
下次还敢Original
2024-04-02 20:54:19596browse

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.

What should I do if I forget my centos username and password?

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

  1. Restart the server and enter GRUB menu.
  2. Press "e" to edit the Linux kernel command line.
  3. Add "rw init=/sysroot/bin/sh" at the end of the line containing "ro".
  4. Press Ctrl x to boot into single-user mode.
  5. Mount the root file system: mount -o remount,rw /.
  6. Reset root password: passwd.
  7. Exit the shell and restart the server.

Method 2: Using Rescue Mode

  1. Boot the server from the CentOS installation ISO image.
  2. Select "Rescue Mode".
  3. Mount the root file system: mount -o remount,rw /.
  4. Copy the chroot environment from the ISO image to the root file system: cp -ax /mnt/sysimage /.
  5. Reset root password: passwd.
  6. Exit the chroot environment: exit.
  7. Unmount the file system: umount /.
  8. 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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn