问题:我想在我的Linux系统上使用sudo来运行一些特权命令,然而当我试图这么做时,我却得到了"[我的用户名] is not in the sudoers file. This incident will be reported."的错误信息。我该怎么处理这种sudo错误呢?

sudo是一个允许特定的用户组用另一个用户(典型的是root)的特权来运行一个命令。sudo有详细的日志功能,并且提供了对用户可通过sudo来运行哪些命令的细粒度控制。

Sudo vs. Su

su命令也提供了同样的特权提升功能,两者不同的是它们认证过程和特权变化的粒度。su允许你从你的登录会话切换到另一个用户的会话,然后你可以随心所欲地用该用户的特权来运行任何程序,但是你需要知道目标用户的密码才能切换这个用户。而另一方面,sudo能在单个命令的基础上工作,允许你用root的特权来运行单个命令。用sudo你不必一定要知道root的密码,但是在提示输入sudo密码的时候要输入你的密码。

在Sudoers列表里添加用户

作为一个新用户的你如果试图运行sudo命令,你会碰到以下错误。意思是你不在这个包含经过认证就可以使用sudo特权的这么一个用户组的sudoers列表里。

  1. [my-user-id]isnotin the sudoers file.This incident will be reported.

有两个方法可以把你加入到sudoers列表中去。

方法一(我试了试貌似不能用, 或者是我的操作不正确, 方法二有效)

第一个方法是把你添加到名为sudo的Linux用户组里。这个特殊的Linux用户组是预配置来使用sudo的。因此,一旦你在这个组里面,那你就可以运行sudo命令了。

以下命令会把你加入到Linux的sudo组里,来确保让你能作为root用户来运行命令。

  1. # adduser <用户名> sudo

现在来确认你的组员资格有没有更新,使用groups命令来看看你当前属于哪个组的列表里。这个列表必定是包含sudo组的。

  1. $ groups

  1. alice adm cdrom sudo dip plugdev fuse lpadmin netdev sambashare davfs2 libvirtd docker promiscuous

组员资格变动(和sudo访问)会在你登出后重新登录后生效。

方法二

第二个能让你使用sudo的方法是直接把你自己添加到 /etc/sudoers 这个配置文件中去。

要修改 /etc/sudoers 文件,你可以使用一个名为visudo的特殊sudo编辑器命令。用root身份简单调用以下命令。

  1. # visudo

这条命令能打开并编辑 /etc/sudoers 文件,将以下这行文字添加至文件末尾,并按Ctrl+X。提示出现时,保存修改退出。

  1. <username> ALL=(ALL) ALL

这个修改会立即生效,你就能马上使用sudo了。

linux解决“XXX is not in the sudoers file”错误的更多相关文章

  1. Linux有问必答:怎样解决“XXX is not in the sudoers file”错误

    问题:我想在我的Linux系统上使用sudo来运行一些特权命令,然而当我试图这么做时,我却得到了"[我的用户名] is not in the sudoers file. This incid ...

  2. 解决:xxx is not in the sudoers file.This incident will be reported.的解决方法

    Linux中普通用户用sudo执行命令时报”xxx is not in the sudoers file.This incident will be reported”错误,解决方法就是在/etc/s ...

  3. 解决ubuntu系统“XXX is not in the sudoers file”错误

    用adduser新建的用户,当时只输入了一个用户名,没做其它操作,这样就建立了一个normal用户.在执行sudo vim hadoop-env.sh时,报“*** is not in the sud ...

  4. Linux sudo 错误:XXX is not in the sudoers file 解决办法

    最近在学习linux,在某个用户(xxx)下使用sudo的时候,提示以下错误:xxx is not in the sudoers file. This incident will be reporte ...

  5. Linux遇到的问题(一)Ubuntu报“xxx is not in the sudoers file.This incident will be reported” 错误解决方法

    提示错误信息 www@iZ236j3sofdZ:~$ ifconfig Command 'ifconfig' is available in '/sbin/ifconfig' The command ...

  6. Linux中添加管理员权限问题:xxx is not in the sudoers file. This incident will be reported.

    在各个不同版本的linux中添加拥有管理员权限账户有不同的简便方式. 问题: 今天遇见将新添用户添加到root用户组后,运行sudo仍然提示 ”xxx is not in the sudoers fi ...

  7. sudo 提示 'xxx is not in the sudoers file.This incident will be reported.的解决方法'

    在使用 Linux 的过程中,有时候需要临时获取 root 权限来执行命令时,一般通过在命令前添加 sudo 来解决. 但是第一次使用 sudo 时,有可能会得到这样一个错误提示 xxx is not ...

  8. centos添加和删除用户及 xxx is not in the sudoers file.This incident will be reported.的解决方法

    修改主机名:vim /etc/sysconfig/network 1.添加用户,首先用adduser命令添加一个普通用户,命令如下: #adduser tommy //添加一个名为tommy的用户 # ...

  9. 企业运维案例:xxx is not in the sudoers file.This incident will be reported” 错误解决方法

    CentOS6系统下,普通用户使用sudo执行命令时报错: xxx is not in the sudoers file.This incident will be reported" 解决 ...

随机推荐

  1. ASP.NET MVC2之Model Binder

    Model Binder在Asp.net MVC中非常简单.简单的说就是你控制器中的Action方法需要参数数据:而这些参数数据包含在HTTP请求中,包括表单上的Value和URL中的参 数等.而Mo ...

  2. 不用IDE写C#的Hello World

    用Visual Studio等IDE写C#的Hello World非常简单,但脱离了IDE你能不能打印出Hello World呢?这不是说工作时脱离IDE,而是学习一下CLR的执行模型. Hello ...

  3. https://www.cnblogs.com/xubing-613/p/5895948.html

    最近总是需要用matplotlib绘制一些图,由于是新手,所以总是需要去翻书来找怎么用,即使刚用过的,也总是忘.所以,想写一个入门的教程,一方面帮助我自己熟悉这些函数,另一方面有比我还小白的新手可以借 ...

  4. SVN详细配置与使用 ——一步步教会您使用

    项目管理在项目开发活动中起到非常重要的作用,而对于初学者来说学习有一定的难度,且不说如何使用,就是搭建过程恐怕也要费一般周折,介于此下面就通过图解的方式一步一步详细的教大家如何使用SVN,你只要耐心的 ...

  5. 操作系统重点双语阅读 - 上下文切换 Context Switch

    The context is represented in the PCB of the process. It includes the value of the CPU registers, th ...

  6. 【转】Linux基础与Linux下C语言编程基础

    原文:https://www.cnblogs.com/huyufeng/p/4841232.html ------------------------------------------------- ...

  7. MySQL连接数过多登录不上

    [mysqld_safe]socket          = /var/run/mysqld/mysqld.socknice            = 0 [mysqld]## * Basic Set ...

  8. Logcat用法初探

    首先定位到adb所在的目录 将手机连接上电脑. 在命令行运行: adb devices 这个命令可以列出所有连上的移动设备. 在命令行运行: adb logcat 可以显示日志.   以下是例子截图: ...

  9. Refuses to install for WTP10

    Refuses to install for WTP10   description http://imgur.com/a/QN4iM I am a WTP10 user. I’m running b ...

  10. [Git] Change the commit message of my last commit

    Did you make a typo in your last commit message? No problem, we can use the git --amend command to c ...