AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / unix / 问题 / 415978
Accepted
Sparhawk
Sparhawk
Asked: 2018-01-10 20:29:00 +0800 CST2018-01-10 20:29:00 +0800 CST 2018-01-10 20:29:00 +0800 CST

使用 vimdiff 时,我可以 sudoedit 可写目录中的文件吗?

  • 772

当我想vimdiff根文件时,我根据这个建议使用以下别名。

alias sudovimdiff='SUDO_EDITOR=vimdiff sudoedit'

然后我可以使用以下命令。

$ sudovimdiff /root/a /root/b

但是,如果我的用户可以写入其中一个文件,则该命令将失败。

$ sudovimdiff /root/a /tmp/b
sudoedit: /tmp/b: editing files in a writable directory is not permitted

有没有办法使用我的用户的环境设置(即)vimdiff 一个根文件和一个非根文件sudoedit?

sudo permissions
  • 2 2 个回答
  • 3707 Views

2 个回答

  • Voted
  1. Best Answer
    ajaaskel
    2018-07-06T02:38:39+08:002018-07-06T02:38:39+08:00

    可能与该 sudoedit 错误消息有关:

    sudoedit: ... 不允许在可写目录中编辑文件

    请尝试使用 修改 sudoers 文件sudo visudo,添加一行:

    Defaults  !sudoedit_checkdir
    

    更多在这里。

    • 4
  2. muru
    2018-01-10T22:13:37+08:002018-01-10T22:13:37+08:00

    从man sudo,在描述-e(又名sudoedit)的部分:

     To help prevent the editing of unauthorized files, the
     following restrictions are enforced unless explicitly allowed
     by the security policy:
    
     ·   Symbolic links may not be edited (version 1.8.15 and
         higher).
    
     ·   Symbolic links along the path to be edited are not
         followed when the parent directory is writable by the
         invoking user unless that user is root (version 1.8.16
         and higher).
     ·   Files located in a directory that is writable by the
         invoking user may not be edited unless that user is root
         (version 1.8.16 and higher).
    

    所以,要么:

    • sudoedit我们以 root 身份调用,这将破坏目的或
    • 我们将用户的文件复制到用户不可编辑的新目录:

      mkdir /tmp/foo
      cp /tmp/b /tmp/foo
      chmod a-w /tmp/foo
      sudoedit /root/a /tmp/foo/b
      
    • 我们编辑根文件并在里面进行比较:

      sudoedit /root/a
      # in Vim
      :vert diffsplit /tmp/b
      
    • 由于sudoedit处理所有非 sudo 参数文件名,您可以使用包装脚本:

      $ cat foo.sh
      #! /bin/sh
      exec vimdiff "$@" "$DIFF_FILE"
      
      $ SUDO_EDITOR ="$PWD/foo.sh" DIFF_FILE="$PWD/.zshrc" sudoedit /etc/zsh/zshrc
      [sudo] password for muru:
      2 files to edit
      sudoedit: /etc/zsh/zshrc unchanged
      
    • 3

相关问题

  • 以非特权用户身份运行时,meld 无法访问 /dev/fd/* 的可能原因是什么?

  • 另一个用户的非空子目录是否可以安全地从我的目录中删除?

  • sudo nautilus 和 sudo -E nautilus 的区别

  • 以其他用户身份运行单个命令;sudo 的限制

  • 允许用户以 root 身份运行命令

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    如何将 GPG 私钥和公钥导出到文件

    • 4 个回答
  • Marko Smith

    ssh 无法协商:“找不到匹配的密码”,正在拒绝 cbc

    • 4 个回答
  • Marko Smith

    我们如何运行存储在变量中的命令?

    • 5 个回答
  • Marko Smith

    如何配置 systemd-resolved 和 systemd-networkd 以使用本地 DNS 服务器来解析本地域和远程 DNS 服务器来解析远程域?

    • 3 个回答
  • Marko Smith

    如何卸载内核模块“nvidia-drm”?

    • 13 个回答
  • Marko Smith

    dist-upgrade 后 Kali Linux 中的 apt-get update 错误 [重复]

    • 2 个回答
  • Marko Smith

    如何从 systemctl 服务日志中查看最新的 x 行

    • 5 个回答
  • Marko Smith

    Nano - 跳转到文件末尾

    • 8 个回答
  • Marko Smith

    grub 错误:你需要先加载内核

    • 4 个回答
  • Marko Smith

    如何下载软件包而不是使用 apt-get 命令安装它?

    • 7 个回答
  • Martin Hope
    rocky 如何将 GPG 私钥和公钥导出到文件 2018-11-16 05:36:15 +0800 CST
  • Martin Hope
    Wong Jia Hau ssh-add 返回:“连接代理时出错:没有这样的文件或目录” 2018-08-24 23:28:13 +0800 CST
  • Martin Hope
    Evan Carroll systemctl 状态显示:“状态:降级” 2018-06-03 18:48:17 +0800 CST
  • Martin Hope
    Tim 我们如何运行存储在变量中的命令? 2018-05-21 04:46:29 +0800 CST
  • Martin Hope
    Ankur S 为什么 /dev/null 是一个文件?为什么它的功能不作为一个简单的程序来实现? 2018-04-17 07:28:04 +0800 CST
  • Martin Hope
    user3191334 如何从 systemctl 服务日志中查看最新的 x 行 2018-02-07 00:14:16 +0800 CST
  • Martin Hope
    Marko Pacak Nano - 跳转到文件末尾 2018-02-01 01:53:03 +0800 CST
  • Martin Hope
    Kidburla 为什么真假这么大? 2018-01-26 12:14:47 +0800 CST
  • Martin Hope
    Christos Baziotis 在一个巨大的(70GB)、一行、文本文件中替换字符串 2017-12-30 06:58:33 +0800 CST
  • Martin Hope
    Bagas Sanjaya 为什么 Linux 使用 LF 作为换行符? 2017-12-20 05:48:21 +0800 CST

热门标签

linux bash debian shell-script text-processing ubuntu centos shell awk ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve