It is advised not to operate regular text editors as the root user, as these editors can perform functions beyond simple text editing, which could be misused by an attacker. To avoid this risk, consider using the 'sudoedit' command. This command creates a temporary copy of the file, opens the text editor as a non-root user, allows editing of the temporary file, and then replaces the original file as root. This way, the text editor does not run with root privileges.
EDITOR=nano sudoedit $path_to_file
- Not specifying
EDITOR
, the system will fallback tovi
- The
EDITOR
variable can be persistently changed in/etc/environment