vimdiff를 사용할 때 쓰기 가능한 디렉터리의 파일을 sudoedit할 수 있나요?

vimdiff를 사용할 때 쓰기 가능한 디렉터리의 파일을 sudoedit할 수 있나요?

루트 파일을 원할 때 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

sudoedit내 사용자의 환경 설정(즉)을 사용하여 루트 파일과 루트가 아닌 파일을 vimdiff하는 방법이 있습니까?

답변1

유용할 수 있는 sudoedit 오류 메시지와 관련:

sudoedit: ...쓰기 가능한 디렉터리의 파일 편집을 허용하지 않습니다.

sudo visudo다음 줄을 추가하여 sudoers 파일을 수정해 보세요 .

Defaults  !sudoedit_checkdir

여기.

답변2

~에서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그것을 루트라고 부르는데, 이는 목적을 무너뜨리거나
  • 사용자가 편집할 수 없는 새 디렉터리에 사용자의 파일을 복사합니다.

    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
    
  • sudo가 아닌 모든 매개변수 파일 이름이 처리 되므로 sudoedit래퍼 스크립트를 사용할 수 있습니다.

    $ 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
    

관련 정보