[Linux] User creation and deletion

content

Shutdown & Restart Commands

basic introduction

Attention to detail

User login and logout

 User Management

basic introduction

Add user

 Specify/modify password

delete users

 Query user information command

 switch user

 View currently logged in users

user group

Instructions for adding groups

delete group command

 Modify user group

User and group related files

 specify runlevel

retrieve root password

help command

manGet help information

 help help command


Shutdown & Restart Commands

basic introduction

shutdown -h now      it is time to shutdown 

shutdown -h      will shutdown in 1 minute" 

shutdown -r now     restarts the computer  now

halt     shutdown, the effect is the same as above 

reboot    now restarts the computer 

sync      synchronizes memory data to disk 

Attention to detail

1. Start the system and shut down the system. First, run the sync command to write the data in the memory to the disk.
2. The current shutdown/reboot/halt and other commands have been synced before shutdown.

User login and logout


basic introduction

1. When logging in, try to log in with the root account as little as possible, because it is the system administrator and has the greatest authority to avoid operation errors. You can log in as a normal user, and then use the "su-username" command to switch to the system administrator identity after logging in.

2. Enter logout at the prompt to log out the user. Ordinary users can switch to root and fall back to ordinary users through logout.

usage details

1. The logout logout command is invalid at the graphical run level, but valid at run level 3.
2. The concept of run level will be introduced later.

  logout test

 The Linux virtual machine cannot logout continuously, using exit just exits the terminal

 On Xshell, you can logout continuously, and you can exit the system by returning to the last one.

 User Management

basic introduction

Linux system is a multi-user and multi-task operating system. Any user who wants to use system resources must first apply for an account to the system administrator, and then enter the system as this account.

Add user

Basic syntax:

useradd username

Applications

Case 1: Add a user milan, the default home directory of the user is /home/milan

Details

1. When the user is successfully created, the home directory with the same name as the user will be automatically created.
2. You can also specify a new user name through useradd -d to specify a home directory for the newly created user.

 Specify/modify password

basic grammar

passwd username  (without writing the username, the default is root to change the password)

show which directory pwd is currently in

Example: Specify password 123456 for milan

 pwd shows which directory it is currently in

delete users

Basic syntax:

userdel username

Example

1. Delete the user milan, but keep the home directory (userdel milan)

2. Delete the user and the user's home directory (userdel -r milan) This operation will delete all the directories under the user, use it with caution

Normally keep home directory

 Query user information command

Basic syntax:

id username

Application example

Query root information

When the user does not exist, the system will prompt that there is no such user

 switch user

Introduction: In operating linux, if the current user has insufficient permissions, you can switch to an advanced user, such as root, through su - user

basic grammar

su - switch user (- with a space before and after)

Example:

Go to a user first, then switch to root

Details:

1. Switching from a user with high authority to a user with low authority does not require entering a password, and vice versa

2. When you need to return to the original user, use the logout/exit command

 View currently logged in users

basic grammar

whoami/who am I

illustrate: 

 whoami is to view the currently logged in user

who am I is to view the last login, and logging in with su is also to view the previous user

user group

introduce

Similar to roles, the system can manage multiple users with commonality in a unified manner

Instructions for adding groups

groupadd group name

delete group command

groupdel group name

Add groups directly when adding users

Command: useradd -g user group username

 Modify user group

grammar:

usermod -g user group username

User and group related files

/etc/passwd file

User (user) configuration file, recording various information
of the user Meaning of each line: Username: Password: User ID: Group ID: Commentary Description: Home Directory: Login Shell

 vim /etc/passwd view, all bash, this file retains user information

/etc/shadow file password configuration file

Meaning of each line: Login Name: Encrypted Password: Last Modified Time: Minimum Time Interval: Maximum Time Interval: Warning Time: Inactivity Time: Expiration Time: Flag

 vim /etc/shadow encrypted password

/etc/group file

The configuration file of the group (group) records the information of the groups contained in Linux The
meaning of each line: group name: password: group identification number: list of users in the group

 specify runlevel

Basic introduction runlevel description:

0: Shutdown
1 Single user [Retrieve lost password]
2: Multi-user status without network service
3: Multi-user status with network service
4: The system is not used and reserved for users
5: Graphical interface
6: System restart

The common run levels are 3 and 5, and the default run level can also be specified, which will be demonstrated later

Application example
Command: init[0123456] Application example: Switch between different run levels through init, such as running 5-3, and then shutting down.

Description of run levels
after CentOS7 Before centos7, the /etc/inittab file was simplified as follows:
multi-user.target : analogous to runlevel 3
graphical.target : analogous to runlevel 5

# To view current default target, run: 
systemctl get-default

# To set a default target, run:
systemctl set-default TARGET.target

retrieve root password

interview questions

how to retrieve root password

1. First, start the system to enter the boot interface, press e in the interface to enter the editing interface

 2. Enter the editing interface, use the up and down keys on the keyboard to move the cursor down, find the number of lines where the content at the beginning of "Linux16" is located, and enter at the end of the line: init=/bin/sh, press the shortcut key ctrl+X after completion enter single user mode

 3. Then enter: mount -o remount,rw / (note: there is a space between each word) in the position where the cursor is flashing, press the Enter key of the keyboard after completion, enter passwd after the new one, and press the Enter key after completion , enter the password, and then confirm the password next time, (the password length is preferably more than 8 digits, but less than 8 digits is also acceptable), after the password is successfully modified, the style of passwd will be displayed, indicating that the root password has been modified successfully.

 4. Enter: touch /.autorelabel (note: there is a space after touch and /) in the position where the mouse is blinking, and press the Enter key after completion

 5. Continue to the next input: exec /sbin/init (note: there is a space after exec and /) and press Enter after completion

 In this way, the password of lroot is retrieved, and you can log in to root directly with the password you just used.

help command

manGet help information

Basic syntax: man command or configuration file ( function description: get help information)

Example: Query the help information of the ls command man ls (press space to display the next page)

Under linux, hidden files start with ., options can be used in combination, such as ls -a to display all files, ls -l to display in a single column, then ls -la or -al can display all files in a single column, such as ls -al /root

 help help command

Basic syntax: help command (function description: get shell to get help information of shell built-in commands)

 Or Baidu direct search related usage

Guess you like

Origin blog.csdn.net/weixin_60719453/article/details/123290881