Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Linux command and its use

2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

1. General mode

Function description

Yy copies the current line of the cursor

Digital + yy copy a few lines

The p arrow moves to the destination line paste

U undo the previous step

Dd deletes the current line of the cursor

Number + dd delete the cursor (inclusive) after the number of lines

X deletes a letter, which is equivalent to del

Capital X removes a letter, which is equivalent to Backspace

Yw copies a word

Dw deletes a word

Shift+ ^ move to the line header

Shift+$ moves to the end of the line

Gg/ first press 1, then press shift+g to move to the top of the page.

G/shift+g moves to the end of the page

Number + shift+g moves to the target line

2. Edit mode

Keypad function

I before the current cursor

An after the current cursor

O the next line of the current cursor line

I the cursor is at the top of the line

A cursor at the end of the line

O the previous line of the current cursor line

3. Instruction mode

Command function

: q! Force to exit the vi command without saving the file

W save the file without exiting the vi command

Wq forces you to write to the file and exit. Force writing even if the file has not been modified, and update the modification time of the file.

: X writes to the file and exits. Write only when the file is modified, and update the file modification time, otherwise the file modification time will not be updated.

/ the word to find, n to find the next, N to look up

? Look for the word you want to find, n find the previous one, and shift+n look down

: set nu displays the line number

: set nonu close line number

4. User and group management commands

Useradd user name (add new user)

Useradd-g group name user name (add a new user to a group)

Passwd user name (set user password)

Id user name (to see if the user exists)

Cat / etc/passwd (see which users have been created)

Userdel user name (delete the user but save the user home directory)

Userdel-r user name (user and user home directory, both deleted)

Whoami (show your own user name)

Usermod-g user group username (modify user group)

Groupadd group name (new group)

Groupdel group name (delete group)

Groupmod-n new group name old group name (modify group)

Cat / etc/group (see which groups have been created)

5. Set ordinary users to have root permissions

1. Add a wang user and set a password for it.

[root@hadoop101 ~] # useradd wang

[root@hadoop101 ~] # passwd wang

2. Modify the configuration file

[root@hadoop101 ~] # vi / etc/sudoers

Modify the / etc/sudoers file, find the following line (line 91), and add a line under root, as follows:

Allow root to run any commands anywhere

Root ALL= (ALL) ALL

Wang ALL= (ALL) ALL

Or you do not need to enter a password when configured to use the sudo command

Allow root to run any commands anywhere

Root ALL= (ALL) ALL

Wang ALL= (ALL) NOPASSWD:ALL

After the modification, you can now log in with your wang account, and then use the command sudo to get root permission to operate.

6. Process running level

7. Forget the root password and reset

Because some systems are installed in English and some in Chinese, the methods are different when modifying them.

English installed system: add init=/bin/sh or rd.break enforcing=0 after rhgb quiet LANG=en_US.UTF-8

System installed in Chinese: add rd.break enforcing=0 after rhgb quiet LANG=zh_CN.UTF-8

In short, we have to achieve a result of three choices in the end.

Rhgb quiet LANG=en_US.UTF-8 init=/bin/sh

Rhgb quiet LANG=en_US.UTF-8 rd.break enforcing=0

Rhgb quiet LANG=zh_CN.UTF-8 rd.break enforcing=0

Press CTRL+X to boot the system with changed parameters.

If the previously entered code is "rhgb quiet LANG=en_US.UTF-8 init=/bin/sh", do the following:

Mount-o remount, rw /

Passwd root # set password and confirm

Exec / sbin/init

Restart-enter a new password-enter

If the code you entered earlier is

Rhgb quiet LANG=en_US.UTF-8 rd.break enforcing=0

Rhgb quiet LANG=zh_CN.UTF-8 rd.break enforcing=0 "does the following:

Mount-o remount, rw / sysroot

Chroot / sysroot

Passwd # enter the new password and confirm the password

Touch / .autorelabel # this step is required if selinux is enabled, and this step may not be performed if selinux is closed!

Mount-o remount,ro / # remount

Exit # exits the exchange interface

Exit # exit the boot interface and restart

All in all, there are two situations

Case 1:init=/bin/sh-> CTRL+X-> mount-o remount, rw /-> passwd root-> exec / sbin/init

Case 2:rd.break enforcing=0-> CTRL+X-> mount-o remount, rw / sysroot-> chroot / sysroot-> passwd-> mount-o remount,ro /-> exit-> exit

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report