linux - 如何修改sudoers?

 LBM-痕迹 发布于 2022-11-01 21:45

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
5 个回答
  • 红帽系的系统默认都有一个管理员组wheel,一般建议把sudo用户添加到这个组。
    用root用户登录后,用visudo命令打开sudoer文件。
    找到

    # %wheel        ALL=(ALL)       ALL

    去掉前面的井号变成

    %wheel        ALL=(ALL)       ALL

    然后用

     usermod -aG wheel 用户名

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

    2022-11-03 10:31 回答
  • tommy ALL=(ALL) NOPASSWD: ALL

    2022-11-03 10:31 回答
  • @依云 说得很有道理。

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

    2022-11-03 10:32 回答
  • 你别听网上瞎说。那句话你随便放哪里都生效。没有 root 那行就没有呗,又不会有什么问题。

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

    更新:

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

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

    export EDITOR=nano
    visudo
    2022-11-03 10:37 回答
  • 经过观察,你这个朴素的做法有个最大的问题:你用 vim 打开文件后,没有翻页。

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

    2022-11-03 10:39 回答
撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有