linux - 如何修改sudoers?
PHPz
PHPz 2017-04-17 17:07:21
0
5
795

centos6.5 新建了一个用户,希望给他root权限,网上说,编辑/etc/sudoers中的

## Allow root to run any commands anywhere
root    ALL=(ALL)     ALL

在后面添加
tommy ALL=(ALL) ALL就好了。

但是我找不到这段话,这段话在哪里?
这是我的sudoers

[root@localhost ~]# vi /etc/sudoers

## Sudoers allows particular users to run various commands as
## the root user, without needing the root password.
##
## Examples are provided at the bottom of the file for collections
## of related commands, which can then be delegated out to particular
## users or groups.
##
## This file must be edited with the 'visudo' command.

## Host Aliases
## Groups of machines. You may prefer to use hostnames (perhaps using
## wildcards for entire domains) or IP addresses instead.
# Host_Alias     FILESERVERS = fs1, fs2
# Host_Alias     MAILSERVERS = smtp, smtp2

## User Aliases
## These aren't often necessary, as you can use regular groups
## (ie, from files, LDAP, NIS, etc) in this file - just use %groupname
## rather than USERALIAS
# User_Alias ADMINS = jsmith, mikem


## Command Aliases
"/etc/sudoers" [readonly] 111L, 3729C
PHPz
PHPz

学习是最好的投资!

全部回复(5)
小葫芦

经过观察,你这个朴素的做法有个最大的问题:你用 vim 打开文件后,没有翻页。

另外,你目前是只读状态,是无法修改该文件的。两罪并罚,请使用 visudo

Peter_Zhu

你别听网上瞎说。那句话你随便放哪里都生效。没有 root 那行就没有呗,又不会有什么问题。

去学一下 sudoers 那些话是什么意思,别只知道从百度出来的乱七八糟的网站上抄抄抄。别忘了魏则西以生命为代价给我们做出的榜样。

更新:

@傅易君 说得很有道理:你试试翻页!

如果你不会使用 vim / vi 的话,可以试试更简单的 nano。用法:

export EDITOR=nano
visudo
伊谢尔伦

@依云 说得很有道理。

正确的方法是使用visudo命令,而不是修改/etc/sudoers文件。

大家讲道理

汤米 ALL=(ALL) NOPASSWD: ALL

左手右手慢动作

红帽系的系统默认都有一个管理员组wheel,一般建议把sudo用户添加到这个组。
用root用户登录后,用visudo命令打开sudoer文件。
找到

# %wheel        ALL=(ALL)       ALL

去掉前面的井号变成

%wheel        ALL=(ALL)       ALL

然后用

 usermod -aG wheel 用户名

把用户添加到wheel组。
这是建议的方式。
附手册Configuring root access

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责声明 Sitemap
PHP中文网:公益在线PHP培训,帮助PHP学习者快速成长!