pkexec visudo

askubuntu原回答摘抄如下

On a modern Ubuntu system (and many other GNU/Linux distributions), fixing a corrupted sudoers file is actually quite easy, and doesn't require rebooting, using a live CD, or physical access to the machine.

To do this via SSH, log in to the machine and run the command pkexec visudo. If you have physical access to the machine, SSH is unnecessary; just open a Terminal window and run that pkexec command.

Assuming you (or some other user) are authorized to run programs as root with PolicyKit, you can enter your password, and then it will run visudo as root, and you can fix your /etc/sudoers.

If you need to edit one of the configuration files in /etc/sudoers.d (which in uncommon in this situation, but possible), use pkexec visudo -f /etc/sudoers.d/filename.

If you have a related situation where you have to perform additional system administration commands as root to fix the problem (also uncommon in this circumstance, but common in others), you can start an interactive root shell with pkexec bash. Generally speaking, any non-graphical command you'd run with sudo can be run with pkexec instead.

(If there is more than one user account on the system authorized to run programs as root with PolicyKit, then for any of those actions, you'll be asked to select which one you want to use, before being asked for your password.)

If that doesn't work--for example, if there are no users authorized to run programs as root via PolicyKit--then boot from an Ubuntu live CD (like the CD you probably used to install Ubuntu) and mount the filesystem for the installed system. You can do this by running sudo parted -l to view your partitions--there is probably just one ext4 partition, and that's the root filesystem.

Suppose the installed Ubuntu system's root filesystem is on /dev/sda1. Then you could mount it with sudo mount /dev/sda1 /mnt. Then you can edit the installed system's sudoers file with sudo nano -w /mnt/etc/sudoers. Or, even better, you can edit it with

sudo visudo -f /mnt/etc/sudoers

(which will prevent you from saving a sudoers file with incorrect syntax).

ubuntu 搞坏了sudoers文件之修复方案的更多相关文章

  1. /etc/sudoers文件损坏修复

    1. 重启(开机)时按Shift键(这时就会进入grub模式) 选择第二项 进入高级选项

  2. Ubuntu 误改/etc/sudoers 文件权限

    添加用户时不小心修改了/etc/sudoers 权限,结果不能sudo了,Ubuntu默认关闭root帐户,结果傻X了,无法改回了. 方法如下: 1.重启机器,开机按ESC,进入恢复模式 2.此时,磁 ...

  3. Ubuntu无法sudo提权,报当前用户不在sudoers文件中错误

    Ubuntu安装后默认root不能登陆系统,密码也是随机生成,其他用户使用root权限,可以使用sudo提权,前提是该用户在/etc/sudoers配置列表中. 但是有时用户名从/etc/sudoer ...

  4. Ubuntu改坏sudoers后无法使用sudo的解决办法

    练习安装odoo的时候,创建了一个odoo用户,想把它赋予sudo权限,然而,编辑的时候不留意,改坏了,导致sudo无法使用,无法编辑sudoers文件修改回来. 总提示如下信息: >>& ...

  5. 烂泥:【解决】ubuntu提示ilanni不在sudoers文件中错误

    本文由秀依林枫提供友情赞助,首发于烂泥行天下. 今天在Ubuntu系统中新建一个用户ilanni,添加完毕后.在执行有关sudo的命令时,提示如下的错误信息:ilanni 不在 sudoers 文件中 ...

  6. Ubuntu系统下解决“YourUserName不在sudoers文件中。此事将被报告”的问题

    本文由荒原之梦原创,原文链接:http://zhaokaifeng.com/?p=624 问题描述: 之前在使用Fedora系统时遇到过在使用 sudo 时提示"YourUserName不在 ...

  7. [错误解决]ubuntu 不在 sudoers 文件中。此事将被报告。

    跟据报错判断,ubuntu没有sudo权限,经过查询需要将ubuntu账户加入/etc/sudoers中 先切换到root权限 su 输入密码 修改/etc/sudoers配置 vim /etc/su ...

  8. sudoers文件设置sudo命令无密码(root密码)登录

    参考博客:http://xvshell.iteye.com/blog/1838093 1. 当用户执行sudo时,Linux系统会去寻找/etc/sudoers文件,并且这是主动的,判断用户是否有执行 ...

  9. 用户名 不在 sudoers文件中,此事将被报告。(转)

    话说昨天新建了一个帐号linc,今天在执行sudo时回显一个很吓人的信息: [sudo] password for linc: linc 不在 sudoers 文件中.此事将被报告. 这是要去哪儿报告 ...

随机推荐

  1. visual studio for mac的安装初体验

    微软2016 Connect 大会发布了visuo studio for mac的pre版本,由于工作原因,现在工作环境是mac,虽然开发现在是在用python,但一直关注着.net的发展,于是自己很 ...

  2. Switch重构处理

    public class Fun{ public void IFNumberid(int flag) { switch (flag) { : Console.WriteLine("优秀&qu ...

  3. Servlet学习笔记

    在这里记录最重要的要点 1,tomcat-->conf-->server.xml里面的东西是什么?(tomcat怎么知道“谁”去处理客户端来的请求?) 最主要的是一个依赖的控制,换句话说什 ...

  4. Windows API Hooking in Python

    catalogue . 相关基础知识 . Deviare API Hook Overview . 使用ctypes调用Windows API . pydbg . winappdbg . dll inj ...

  5. 设置session,cookies

    Cookie cookie = new Cookie("username",username); cookie.setMaxAge(60 * 60 * 24 * 365 * 2); ...

  6. python网络编程

    Socket是网络编程的一个抽象的概念. 通常我们用一个Socket表示"打开了一个网络链接",而打开一个Socket需要知道目标计算机的IP地址和端口号,再指定协议类型即可. 套 ...

  7. linux tomcat 启动

    在tomcat bin目录下启动时报权限不够 在bin目录下输入:chmod u+x *.sh 可解决 查看tomcat 是否关闭 ps -ef|grep java 例如显示如下 说明还没关闭root ...

  8. EmployeeTest

    package fourthf; public class EmployeeTest { public static void main(String[] args) { // TODO Auto-g ...

  9. 使用Python解析JSON数据

    使用Python解析百度API返回的JSON格式的数据 # coding:utf-8 # !/usr/bin/env python import matplotlib.pyplot as plt fr ...

  10. Spring特性--DI

    DI:Dependency Injection(依赖注入),通俗的讲就是一种通过xml配置文件,为交给sping容器的对象初始化参数.又称做控制反转:Inversion of Control(IoC) ...