Linux from entry to abandonment (3) user management

After understanding the basic directory structure of linux, let's understand the knowledge point of user and file permission management.

1. Basic introduction:

Linux is an operating system that can achieve multi-user login. For example, "Guihai" and "Fengge" can both log in to the same host at the same time. They share some host resources, but they also have their own user space for storage. respective files. But in fact their files are placed on the same physical disk or even in the same logical partition or directory, but due to Linux's user management and permission mechanism , different users cannot easily view and modify each other's files.

2. View the login user information: who am i

In fact, there are two commands like who am i , who -m and who mom likes respectively . This depends on personal preference.

 

Note: in some environments the who am iand who mom likescommand will not output anything, this is because the SHELL currently in use is not the SHELL at login, and there is no user associated with who's stdin, so nothing will be output. For example, I type this command on my local Ubuntu system without prompting.

whoOther common parameters of the command:

 

3. Add user: useradd username

In a Linux system, rootan account has the supreme authority of the entire system, such as creating and adding users.

1) Introduction to root:

Root authority, a type of system authority, and SYSTEM authority can be understood as a concept, but higher than Administrator authority, root is the super administrator user account in Linux and UNIX systems, this account has the supreme power of the entire system, all objects he All can be operated, so many hackers have to upgrade their privileges to root privileges when invading the system. This operation is equivalent to adding the newly created illegal account to the Administrators user group under Windows. For example, in the Android operating system (based on the Linux kernel), after obtaining the root authority, it means that you have obtained the highest authority of the mobile phone. At this time, you can perform all additions, deletions, changes, and inspections to any file (including system files) in the mobile phone. operation.

2) How to log in to root: su or su root

su <user>You can switch to the user user, you need to enter the password of the target user when executing, sudo <cmd>you can run the cmd command at the privilege level, you need the current user to belong to the sudo group, and you need to enter the password of the current user. su - <user>The command also switches users, but at the same time, the user's environment variables and working directory will also be changed to those corresponding to the target user.

It should be noted that the password entered in the Linux environment will not be displayed the same as the mysql command line

3) Add user: useradd cat

Since I added cat before, I am adding a fish user here.

How do we know if we have added successfully?

  • First, see if there is anything on the command line. If there is no "movement" in linux, the operation is successful.

  • Second, you can use the su command to switch to your newly created user.

  • Third, you can also view your user list in the home directory.

  • Fourth cat /etc/passwd to see which users have been created

You can exit directly as a fish user if you want to quit.

4) Add a password to the user: passwd fish

 

In fact, the password does not matter to the individual, and the prompt can be ignored.

5) Add users to groups (the concept of groups will be discussed later)

useradd -g group name user name (function description: add a new user to a group)

 

4. Delete user: userdel username

1) Delete user fish, but keep the home directory: userdel fish

2) Delete the user and user home directory: userdel -r tom

5. Query user information: id username

Here we view cat user information.

 

Note: When the user does not exist, return no such user. Let's take the fish deleted above as an example.

6. Switch user: su username

I've used this a lot before, it's simple and practical.

In operating Liunx, if the current user has insufficient permissions, you can switch to a high-privileged user, such as root, through the su - command.

 

Additional 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 exit and logout commands.

7. sudo set ordinary users to have root privileges:

1) Add a user and set a password for it (I have this above)

useradd cat

passwd cat

2) Modify the configuration file

vi /etc/sweats

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

Just put all your users on the list.  

 

8. Modify user: usermod -g user group user

1) Basic syntax usermod -g user group username

2) Option description Table 7-18 Option function -g Modify the user's initial login group, the given group must exist. The default group id is 1.

3) Example: Add the user to the user group [root@hadoop101 opt]# usermod -g

Guess you like

Origin blog.csdn.net/OMGcome/article/details/124284547