Home  >  Q&A  >  body text

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 days ago805

reply all(5)I'll reply

  • 高洛峰

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

    After observation, there is a biggest problem with your simple approach: after you open the file with vim, the pages are not turned.

    In addition, you are currently in read-only status and cannot modify the file. Both crimes are punishable, please use visudo.

    reply
    0
  • 天蓬老师

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

    Don’t listen to nonsense on the Internet. That sentence will take effect wherever you put it. If you don't have root, it won't work, and there won't be any problem.

    Go and learn what those words sudoers mean, don’t just copy them from the messy websites from Baidu. Don’t forget the example Wei Zexi set for us at the cost of his life.

    Update:

    @Fu Yijun makes sense: try turning the page!

    If you don’t know how to use vim/vi, you can try the simpler nano. Usage:

    export EDITOR=nano
    visudo

    reply
    0
  • 伊谢尔伦

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

    @Evian makes sense.

    The correct way is to use visudo命令,而不是修改/etc/sudoersfiles.

    reply
    0
  • 大家讲道理

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

    tommy ALL=(ALL) NOPASSWD: ALL

    reply
    0
  • ringa_lee

    ringa_lee2017-04-17 17:09:21

    Red Hat systems have an administrator group wheel by default. It is generally recommended to add the sudo user to this group.
    After logging in as the root user, use the visudo command to open the sudoer file.
    Found

    # %wheel        ALL=(ALL)       ALL

    Remove the pound sign in front and it becomes

    %wheel        ALL=(ALL)       ALL

    Then use

     usermod -aG wheel 用户名

    Add user to wheel group.
    This is the recommended way.
    With manual Configuring root access

    reply
    0
  • Cancelreply