Linux中sudo的用法

在linux中的用户只有2种:root和非root。而非root即普通用户的权限很是低,基本处理本身的home目录,其余好多地方连查看的权利也没有,更不要说安装软件了。linux

为了不来回切换root,linux加入了sudo命令,即:能够临时切换的root来执行一些系统命令,用完以后,在返回普通用户,这样既避免长期使用root带来的安全风险,安全

又有效的减小了切换root的频率。ide

一、sudo命令的配置主配置文件:/etc/sudoers,不过,系统文档推荐的作法,不是直接修改/etc/sudoers文件,而是将修改写在/etc/sudoers.d/目录下的文件中。ui

任何在/etc/sudoers.d/目录下,不以~号结尾的文件和不包含.号的文件,都会被解析成/etc/sudoers的内容。另外要注意:若是使用这种方式修改sudoers,this

须要在/etc/sudoers文件的最后行,加上#includedir /etc/sudoers.d语句(默认已有)。spa

注意了,这里的指令#includedir是一个总体, 前面的#号不能丢,也不能在#号后有空格。而且,尽量使用visudo来编辑sudoers, 由于有相关的错误识别机制。code

相关文档:文档

# This will cause sudo to read and parse any files in the /etc/sudoers.d
# directory that do not end in '~' or contain a '.' character.

# Note that there must be at least one file in the sudoers.d directory (this
# one will do), and all files in this directory should be mode 0440.

# Note also, that because sudoers contents can vary widely, no attempt is
# made to add this directive to existing sudoers files on upgrade.

# Finally, please note that using the visudo command is the recommended way
# to update sudoers content, since it protects against many failure modes.
string

二、具体的配置命令it

相关文章
相关标签/搜索