LinuxCommandLibrary

sudoedit

Safely edit files with elevated privileges

TLDR

Edit file as root

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

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 editor
VISUAL - Visual editor
EDITOR - Default editor

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)

> TERMINAL_GEAR

Curated for the Linux community

Copied to clipboard

> TERMINAL_GEAR

Curated for the Linux community