It is usually used when converting users.suUser's way. ButsuThe mode needs to know the user password to switch. Andsu RootToRooAccount,RootThe account has full permissions. To preventRootThe account did wrong, so there wassudo's command.sudoName impliesSuper User doIt allows ordinary accounts to executeRootThe permissions of the account.
Other accounts can performsudoHave to be in/etc/sudoersFile, this file is onlyRootAccount to edit. must also useVisudoEdit. The reason forVisudoThere are two reasons:1Prevents two users from modifying at the same time2Can perform a limited grammar check.
Before adding permissions, let's take a look at the current account's permissions, for example, we want to see the contents of the /etc/shadow file. Prompt for no permission when querying with ZHF account. The reason is that this file only has access to the root account.
[Email Protected]:~/zhf$cat/etc/shadow
Cat:/etc/shadow:permission denied
Run the visudo command. Add %zhf all= (all:all) all
#Allow members of the group sudo to execute any command
%sudo all= (All:all) all
%ZHF all= (All:all) all
zhf is a user account. First all represents the host number of the login source.
(All:all) stands for convertible identity, we can set other account names inside such as zhf_test:zhf . So when using the command Sudo-u zhf_test will be zhf_test to execute the command. sudo-u ZHF will be zhf 's identity to execute the command.
The last all represents an executable command. Here we give ZHF all the root executable commands. After adding, we continue to execute the previous command. This time to use Sudocat/etc/shadow to execute. After entering your username and password, you can see the contents of the etc/shadow file.
[Email Protected]:~/zhf$sudo Cat/etc/shadow
[Sudo]password for ZHF:
Root:$3$2lx7mdyc$upa1ssj61rghwutonnkxj1hqxeal71xsiio4tnyiwdhriytkyimdhtia9e6w0wkpd9kxis5psm7977/njdkn9. : 783420:111111:7:::
In addition, the following line is the sudo permission of the group members user of the configuration groups.
#Members of the admin group may gain root privileges
%adminall= (All) all
/etc/sudoers Configure all permissions for other accounts There are also many security implications. So we generally have constraints on the commands that the account can execute. For example, the following on ZHF account was constrained, granted ifconfig As well as ls root permissions. Other commands do not involve the
%ZHF all= (All:all) Sbin/ifconfig,/bin/ls
To learn Linux:sudo.