username is not in the sudoers file问题

在使用Linux的过程中,当使用普通用户执行某些程序被告知没有权限时,需要临时升级权限,但又不想切换到root用户,这时可以使用sudo命令,比如这样。

sudo service mysqld start

但是,使用sudo也是需要权限的,如果你的管理员(可能是你自己)没有给你的普通用户开放权限,就会遇到下面的问题。

[gap@localhost Desktop]$ sudo service msyqld start

We trust you have received the usual lecture from the local System
Administrator. It usually boils down to these three things:

    #1) Respect the privacy of others.
    #2) Think before you type.
    #3) With great power comes great responsibility.

[sudo] password for gap: 
gap is not in the sudoers file.  This incident will be reported.

这时,需要管理员使用root用户操作,给普通用户增加这个权限,主要是修改/etc/sudoers 文件,但这个文件对root用户也是只读的,所以要给这个文件增加写权限。

[root@localhost etc]# ll sudoers
-r--r-----. 1 root root 4000 Mar  6  2015 sudoers
[root@localhost etc]# chmod u+w sudoers
[root@localhost etc]# ll sudoers
-rw-r-----. 1 root root 4018 Oct 21 23:49 sudoers

使用vi编辑sudoers文件。

[root@localhost etc]# vim sudoers

root ALL=(ALL) ALL的下一行增加一个普通用户的授权,如下。

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

最后,把sudoers文件的权限恢复。

[root@localhost etc]# chmod u-w sudoers
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值