sudoedit

Safely edit files with elevated privileges

TLDR

Edit file as root
$ sudoedit [/etc/hosts]
Edit with specific editor
$ SUDO_EDITOR=[vim] sudoedit [/etc/fstab]
Edit multiple files
$ sudoedit [/etc/file1] [/etc/file2]
Edit as another user
$ sudoedit -u [username] [file]

SYNOPSIS

sudoedit [-u user] [options] files

DESCRIPTION

sudoedit safely edits files with elevated privileges. It's equivalent to sudo -e.File is copied to temp location. User edits with their own editor.After editing, changes copy back. Original file replaced atomically.User's environment is preserved. Editor runs as the user, not root.Safer than running editor as root. Limits privilege escalation risks.

PARAMETERS

-u, --user USER

Edit as user.
-g, --group GROUP
Edit with group.
-H
Set HOME.
-n, --non-interactive
Non-interactive mode.

ENVIRONMENT

SUDO_EDITOR - Preferred editorVISUAL - Visual editorEDITOR - Default editor

INSTALL

sudo apt install sudo
sudo dnf install sudo
sudo pacman -S sudo
sudo apk add sudo
sudo zypper install sudo
nix profile install nixpkgs#sudo

CAVEATS

Editor plugins run as user. Some editors may not work. Temp files briefly exist.

HISTORY

sudoedit is part of sudo, providing secure file editing. It prevents running arbitrary code with root privileges through editor extensions.

SEE ALSO

sudo(8), visudo(8), vi(1)