How to change the password of Centos7 root user and ordinary user if they forget it?

1. Change root user password

1. Restart the virtual machine and click E on the startup interface to enter this interface
Insert image description here
. 2. Enter init=/bin/sh in UTF-8 (keep scrolling down) and then press CTRL+X to enter this interface.
Insert image description here
3. Enter mount - o remount, rw /
and then enter passwd to change the root password. You need to enter the new password twice.Insert image description here

4. After changing the password, enter touch /.autorelabel
exec /sbin/init to restart the system
and wait quietly for a while.
Insert image description here

2. Change ordinary user password

1.首先切换到root用户下
2.然后输入passwd 用户名 
3.修改用户密码

Insert image description here

Summarize

I have forgotten my password twice. It is recommended to use notepad to record your password.

Modify username (hostname)
sudo hostnamectl set-hostname

Guess you like

Origin blog.csdn.net/tyloonulinuli/article/details/122511765