sudo Introduction to Commands:
Make a user execute a command as another user
1 . The configuration file is:/etc/sudoers
configuration file format:
Format: Who which_hosts= (runas) command
Who: Indicates which user which_hosts: which host
runas: What user is executing command: What commands to execute
For multiple users, logging on to multiple servers, executing multiple identities, multiple commands, and defining aliases:
Who:user_alias User Aliases
Which_hosts:host_alias Host Aliases
Runas:runas_alias with what user alias
Command:cmnd_alias command Aliases
Aliases must all and only use a combination of uppercase English letters:
User alias Definition Format:
User_alias useradmin = System User name,% group name, and other user aliases that you have defined
User aliases: Can include: System user name, group name (format:% group name), other defined user aliases in the middle, separated by
Host alias definition Format:
Host_alias hostadmin = host name, IP address, network address segment, other defined host aliases
Runas_alias alias Format:
Runas_alias runasname = user name,% group name, other defined runas aliases
Cmnd_alias Command alias Format:
Cmnd_alias COMMANDNAME = command path, directory (all commands in this directory), other pre-defined command aliases
Usage: Enables Hadoop users to execute useradd usermod commands for all hosts
Vim/etc/sudoers Edit the sudo configuration document and add the following on the last line:
Hadoop all= (Root)/usr/sbin/useradd,/usr/sbin/usermod
2 . Command function:
enables one user to execute a command on a host as another user
3 . Command parameters:
-L: Lists all sudo class commands that the current user can use
-K: Disable authentication information (default sudo remembers password for 5 minutes)
Add Tag: nopasswd:passwd:
4 . Command instance:
1. Enable Hadoop users to execute useradd usermod commands for all hosts
Vim/etc/sudoers Edit the sudo configuration document and add the following on the last line:
Hadoop all= (Root) nopasswd:/usr/sbin/useradd,/usr/sbin/usermod
NOPASSWD: No password is required for all commands that are behind the label
Hadoop all= (Root) nopasswd:/usr/sbin/useradd, PASSWD:/usr/sbin/usermod
PASSWD: Indicates the need for a password,
2. Enable the Sudoers profile using alias mode
Vim/etc/sudoers
User_alias useradmin = hadoop,%hadoop,%useradmin #表示hadoop用户, Hadoop Group, useradmin Group
Cmnd_alias useradmincmnd =/usr/sbin/useradd,/usr/sbin/usermod,/user/bin/passwd [A-Za-z]*,! /USR/BIN/PASSWD root #命令别名, which means that useradd usermod/user/bin/passwd can be executed via sudo [a-za-z]* means that the Execute passwd command must be followed by at least one letter! /USR/BIN/PASSWD root indicates that you cannot execute the passwd root command (!) to modify the root user password
useradmin all= (Root) nopasswd:useradmincmnd
[Email protected] root]$ SUDO/USR/SBIN/PASSWD root
Password:
John is isn't in the sudoers file. This incident would be reported.
[Email protected] ~]$ SUDO/USR/BIN/PASSWD
Sorry, user John is not allowed to execute '/usr/bin/passwd ' as the root on Localhost.localdomain.
[Email protected] ~]$ sudo/usr/bin/passwd Donggen
Changing password for user Donggen.
New UNIX Password:
Bad Password:it is the too short
Retype new UNIX Password:
Passwd:all authentication tokens updated successfully.
This article is from the "Learn Linux history" blog, please be sure to keep this source http://woyaoxuelinux.blog.51cto.com/5663865/1887356
Linux commands: About sudo