Linux Chapter 2: Modify the root password and shutdown and restart commands

Linux command summary

1.1 Correct switch and password

1.1.1 Shut down or restart

  • shutdown -h now [Shut down immediately]
  • shutdown -h 1 [Shut down in one minute]
  • shutdown -r now [restart now]
  • shutdown -r 2 [Restart in two minutes]
  • halt [shut down immediately]
  • reboot [restart immediately]
  • Before shutting down and restarting, you need to write memory data to disk to execute sync

1.1.2 User login and logout

  • Switch user : su user name, if no user name is added, the default is to root
  • Logout user : logout, different shell exits are different, or logout exit is the launch of xshell.

2. Password problem

2.1 Common sense of password input

  • The linux passwords are all palindrome-free, and you can enter it without displaying your input. Try not to use the small keyboard, otherwise the password will be wrong.

2.2 Retrieve root password

1. Control the up and down keys within three seconds after the computer is turned on to prevent the system from selecting itself

linux boot state diagram

2. After positioning on the first line, press the letter e to edit, you will enter another interface (emergency preliminary interface)
linux emergency mode
3. Change the ro in the line starting with linux16 (mine is at the end of the last line), ro to rw init=/sysroot/bin/bash, as shown in the figure below
Modify linux ro value
4. Press Ctrl + x at the same time, the system will actually enter the emergency mode, as shown in the figure below
Enter linux emergency mode
5. First switch to the original system and then modify the root password, chroot is used to switch the system, /sysroot is the original system (centos7), the passwd command is to modify the root password, and the password will be garbled. Just enter it twice. Another solution is to enter LANG=en (must be capitalized) , And then enter passwd. After the password is changed, you need to execute touch /.autorelabel (to make SELinux take effect). After the execution, press Ctrl + d at the same time, and then enter reboot again.
To linux original system

3. Use shortcut keys

  • Ctrl + C : End the current command. If you enter a large string of characters and don't want to enter it, use the Ctrl+C key combination, and it will jump to the next line, leaving a ^C mark at the cursor.
  • Ctrl + Z : Pause the current process. After pausing, you can resume the process with the fg command, and Ctrl + C will kill it directly.
  • Ctrl + L : Clear the screen, move the cursor to the first line, because our cursor always looks uncomfortable on the last line after executing the command multiple times, we can perform the so-called clear screen.
  • Ctrl + A : Move the cursor to the front of the command. When we need to modify the command we just entered, we can quickly move to the beginning of the line.
  • Ctrl + E : You can move the cursor to the last line of the command.
  • Ctrl + D : Exit the current terminal, you can also use exit to achieve.
  • Arrow keys up or down : view the previous or next instruction

Thank you all for reading. Due to the limited ability of the editor, please contact me if you have any objections to the compilation.

Guess you like

Origin blog.csdn.net/qq_44112474/article/details/103335925