什么是sudo sudo是用来执行需要提升权限的命令。
Sudo配置 1 # visudo sudo执行命令的流程 当用户执行sudo时,系统会主动寻找/etc/sudoers文件,判断该用户是否有执行sudo权限 确认用户具有可执行的权限后,让用户输入自己的密码确认 若密码输入成功,则开始执行sudo后续的命令 不需要密码的情况 root执行sudo时不需要输入密码(sudoers文件中有配置root ALL=(ALL)ALL这样一条规则)
要切换的身份与执行者的身份相同,不需要输入密码
/etc/sudoers文件设置为允许用户在不输入该用户密码的情况下使用所有命令
如设置允许wheel用户组中的用户在不输入该用户的密码的情况下使用所有命令
%wheel ALL=(ALL) NOPASSWD:ALL
/etc/sudoers文件解释 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 ## cat /etc/sudoers ## 下面是规则配置:什么用户在哪台服务器上可以执行哪些命令(sudoers文件可以在多个系统上共享) ## Syntax: ##语法 ## user MACHINE=COMMANDS ## 用户 登录的主机=(可以变换的身份) 可以执行的命令 ## ## The COMMANDS section may have other options added to it. ## 命令部分可以附带一些其它的选项 ## ## Allow root to run any commands anywhere ## 允许root用户执行任意路径下的任意命令 root ALL=(ALL) ALL ## Allows members of the 'sys' group to run networking, software, ## service management apps and more. # %sys ALL = NETWORKING, SOFTWARE, SERVICES, STORAGE, DELEGATING, PROCESSES, LOCATE, DRIVERS ## 允许sys中户组中的用户使用NETWORKING等所有别名中配置的命令 ## Allows people in group wheel to run all commands # %wheel ALL=(ALL) ALL ## 允许wheel用户组中的用户执行所有命令 ## Same thing without a password ## 允许wheel用户组中的用户在不输入该用户的密码的情况下使用所有命令 # %wheel ALL=(ALL) NOPASSWD: ALL ## Allows members of the users group to mount and unmount the ## cdrom as root ## 允许users用户组中的用户像root用户一样使用mount、unmount、chrom命令 # %users ALL=/sbin/mount /mnt/cdrom, /sbin/umount /mnt/cdrom ## Allows members of the users group to shutdown this system # %users localhost=/sbin/shutdown -h now ## 允许users用户组中的用户像root用户一样使用shutdown命令 sudo执行命令的流程 sudo会话 sudo默认在输入一次密码后15分钟内不会再次要求密码。15分钟后,你会再次被要求输入密码。
...