Home  >  Article  >  Operation and Maintenance  >  What to do if you forget your password to log in to centos

What to do if you forget your password to log in to centos

下次还敢
下次还敢Original
2024-04-07 19:33:25935browse

Solutions for forgotten CentOS passwords include: Single-user mode: Enter single-user mode and use passwd root to reset the password. Rescue Mode: Boot from CentOS Live CD/USB, mount root partition and reset password. Remote access: Use SSH to connect remotely and reset the password with sudo passwd root.

What to do if you forget your password to log in to centos

How to log into CentOS if you forgot your password

Forgetting your CentOS password can be frustrating, but There are several ways to reset your password and regain access to your system.

Method 1: Single User Mode

  • Restart the server and hold down the Shift key to enter the GRUB menu.
  • Select "Advanced Options" and then select the entry labeled "Single User Mode".
  • You will be prompted to enter the root password. Since you forgot your password, press Enter to skip this step.
  • The system will boot into single user mode.
  • Reset the root password using the following command:
<code>passwd root</code>
  • Enter and confirm your new password.
  • Type the reboot command to restart the server.

Method 2: Rescue Mode

  • Boot the server using CentOS Live CD/USB.
  • When prompted to select a language, select "Rescue Mode".
  • The system will load the rescue system.
  • Mount the root partition:
<code>mount /dev/sdaX /mnt</code>
  • Reset the password in the mounted root partition:
<code>chroot /mnt
passwd root</code>
  • Exit chroot And remount the root partition:
<code>exit
umount /mnt</code>
  • Type the reboot command to restart the server.

Method 3: Remote Access

If your server is accessible via SSH, you can reset the forgotten password using a remote account:

  • Connect to the server using SSH:
<code>ssh username@server_ip</code>
  • At the remote prompt, use the following command to reset the root password:
<code>sudo passwd root</code>

Tip:

  • Choose a strong password and change it regularly.
  • Consider using a password manager to store your passwords securely.
  • If you forget another user's password, you can use the same process to reset them.

The above is the detailed content of What to do if you forget your password to log in to centos. 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