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

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

Apr 02, 2024 pm 08:54 PM
linux centos

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 of this Website
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to solve the permissions problem encountered when viewing Python version in Linux terminal? How to solve the permissions problem encountered when viewing Python version in Linux terminal? Apr 01, 2025 pm 05:09 PM

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 permissions of unixsocket after system restart? How to automatically set permissions of unixsocket after system restart? Mar 31, 2025 pm 11:54 PM

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...

Why does an error occur when installing an extension using PECL in a Docker environment? How to solve it? Why does an error occur when installing an extension using PECL in a Docker environment? How to solve it? Apr 01, 2025 pm 03:06 PM

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

How to efficiently integrate Node.js or Python services under LAMP architecture? How to efficiently integrate Node.js or Python services under LAMP architecture? Apr 01, 2025 pm 02:48 PM

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...

How to solve permission issues when using python --version command in Linux terminal? How to solve permission issues when using python --version command in Linux terminal? Apr 02, 2025 am 06:36 AM

Using python in Linux terminal...

Can the Python interpreter be deleted in Linux system? Can the Python interpreter be deleted in Linux system? Apr 02, 2025 am 07:00 AM

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...

What should I do if Beyond Compare fails to case sensitivity when synchronizing Windows and Linux files? What should I do if Beyond Compare fails to case sensitivity when synchronizing Windows and Linux files? Apr 01, 2025 am 08:06 AM

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

How to configure apscheduler timing task as a service on macOS? How to configure apscheduler timing task as a service on macOS? Apr 01, 2025 pm 06:09 PM

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...

See all articles