首頁  >  問答  >  主體

linux - 如何修改sudoers?

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
PHPzPHPz2742 天前807

全部回覆(5)我來回復

  • 高洛峰

    高洛峰2017-04-17 17:09:21

    經過觀察,你這個樸素的做法有個最大的問題:你用 vim 打開文件後,沒有翻頁。

    另外,你目前是唯讀狀態,是無法修改該檔案的。兩罪併罰,請使用 visudo

    回覆
    0
  • 天蓬老师

    天蓬老师2017-04-17 17:09:21

    你別聽網路上瞎說。那句話你隨便放哪裡都生效。沒有 root 那行就沒有唄,又不會有什麼問題。

    去學一下 sudoers 那些話是什麼意思,別只知道從百度出來的亂七八糟的網站上抄抄抄。別忘了魏則西以生命為代價給我們所做的榜樣。

    更新:

    @傅易君 說得很有道理:你試試翻頁!

    如果你不會使用 vim / vi 的話,可以試試更簡單的 nano。用法:

    export EDITOR=nano
    visudo

    回覆
    0
  • 伊谢尔伦

    伊谢尔伦2017-04-17 17:09:21

    @依雲 說得很有道理。

    正確的方法是使用visudo命令,而不是修改/etc/sudoers檔案。

    回覆
    0
  • 大家讲道理

    大家讲道理2017-04-17 17:09:21

    湯米 ALL=(ALL) NOPASSWD: ALL

    回覆
    0
  • ringa_lee

    ringa_lee2017-04-17 17:09:21

    紅帽系的系統預設都有一個管理員群組wheel,一般建議把sudo使用者加入這個群組。
    用root使用者登入後,用visudo指令開啟sudoer檔案。
    找到

    # %wheel        ALL=(ALL)       ALL

    去掉前面的井號變成

    %wheel        ALL=(ALL)       ALL

    然後用

     usermod -aG wheel 用户名

    把用戶加到wheel群組。
    這是建議的方式。
    附手冊Configuring root access

    回覆
    0
  • 取消回覆