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

What is the method for Linux to switch users?

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

This article mainly introduces the relevant knowledge of what is the method of Linux switching users, the content is detailed and easy to understand, the operation is simple and fast, and it has a certain reference value. I believe you will gain something after reading this Linux switching user method. Let's take a look at it.

one。 Susu is used to switch between users, but the user remains logged in before the switch. If you switch from root to normal, you don't need a password. On the contrary, an ordinary user who switches to any other user needs password authentication.

Su switches to the root user by default without any parameters, but not to the root user root directory; su plus the parameter-means to switch to the root user by default and to the root user root directory.

The obvious drawback of su is that if a user needs to use root privileges, he or she must tell that user the root password.

User before the exit is returned: exit

Switch to git user

[root@iZ2ze9twtxjrbirmldp9owZ ~] # su git [git@iZ2ze9twtxjrbirmldp9owZ root] $pwd / root [git@iZ2ze9twtxjrbirmldp9owZ root] $exit exit [root@iZ2ze9twtxjrbirmldp9owZ ~] # 123456 the following operations are performed by logging in to the client using the user

[@centos6-1 ~] $su Password: [root@centos6-1 ] # pwd / home/ [root@centos6-1 ] # exit exit [@centos6-1 ~] $su-Password: [root@centos6-1 ~] # pwd / root [root@centos6-1] # 1234567891011 II. Sudosudo is designed for all ordinary users who want to use root permissions, so that ordinary users can have the right to use root permissions temporarily, just enter the password of their own account. Of course, this ordinary user must have a configuration entry in the / etc/sudoers file to have the right to use sudo.

Ordinary users cannot perform root permission operations without configuration permissions:

[@centos6-1 ~] $pwd / home/ [@centos6-1 ~] $ll / root/ ls: cannot open directory / root/: Permission denied [@centos6-1 ~] $12345 cannot use sudo until there is no configuration permission

[@centos6-1] $sudo ls / root/ [sudo] password for : is not in the sudoers file. This incident will be reported. [@centos6-1 ~] $1234 configure sudo permissions for users using root login, enter visudo on the command line, and open the / etc/sudoers file. Note that it is not recommended to modify it directly by vi / etc/sudoers

# # Allow root to run any commands anywhere root ALL= (ALL) ALL / / find the line ALL= (ALL) ALL / / in the file and add this line below it, so that can use sudo to execute the command of root permission # # Allows members of the 'sys' group to run networking, software, # # service management apps and more. #% sys ALL = NETWORKING, SOFTWARE, SERVICES, STORAGE, DELEGATING, PROCESSES, LOCATE, DRIVERS123456 log in to the client operation again with the user, and found that it is successful

[@centos6-1 ~] $sudo ls / root/ [sudo] password for : anaconda-ks.cfg install.log install.log.syslog license notice [@centos6-1 ~] $1234sudo works as follows:

1. When a user executes sudo, the system will actively look for the / etc/sudoers file to determine whether the user has the authority to execute sudo. After confirming that the user has the permission to execute sudo, let the user enter his own password to confirm 3. If the password is entered successfully, the subsequent commands of sudo will be executed as configured in the 123/etc/sudoers file.

The first ALL of ALL= (ALL) ALL refers to a host in the network, and we can specify a host name so that can only execute subsequent commands on this host. The ALL in the second parenthesis refers to the target user, that is, in whose capacity the command is executed. The last ALL refers to the command name.

Haha centos6-1 = (zaomianbao) / bin/kill / / only allow users to execute kill commands centos6-1=NOPASSWD:/bin/ls on centos6-1 as zaomianbao users, / bin/cat / / only allow users to execute ls on centos6-1 as root, cat commands 12 We modify to the second form centos6-1=NOPASSWD:/bin/ls, / bin/cat

[@centos6-1 ~] $sudo ls / root/anaconda-ks.cfg install.log install.log.syslog license notice [@centos6-1 ~] $sudo cat / root/anaconda-ks.cfg # Kickstart file automatically generated by anaconda. # version=DEVEL install cdrom [@centos6-1 ~] $sudo vi / root/anaconda-ks.cfg [sudo] password for : Sorry, user is not allowed to execute'/ bin/vi / root/anaconda-ks.cfg' as root on centos6-1. [@centos6-1] $1234567891011 you can see that the user has the permissions of ls and cat, but not the right of vi

This is the end of the article on "what is the method of switching users on Linux?" Thank you for reading! I believe that everyone has a certain understanding of the knowledge of "what is the method of Linux switching users". If you still want to learn more knowledge, you are welcome to follow the industry information channel.

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

Development

Wechat

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

12
Report