Linux中sudo的用法

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

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

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

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

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

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

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

相关文档:

# 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.

2、具体的配置命令

posted @ 2017-06-06 07:56  立体风  阅读(3271)  评论(0编辑  收藏  举报