It doesn’t edit the file directly, it creates a temp file that replaces the file when saving. It means that the editor is run as the user, not as root.
So it opens the file in your editor, since you have read access to it. Then saves your changes to a temp file. Then when you close the editor it does a sudo mv tmpfile readfile?
I checked this by checking the file ownership when running touch myself. The file is owned by root. sudo nano myself also creates a file owned by root. sudoedit myself bitches at me not to run it in a writable directory.
sudoedit: myself: editing files in a writable directory is not permitted
So I ran it in a non-writable directory and the resulting file is still owned by root.
So is the advantage of sudoedit preventing a possible escalation of privileges situation?
For me personally the advantage is that since the editor is opened by your user, it has all of the same config that I’m used to (such as my souped up Neovim config).
Whereas if you sudo nvim /path/to/file then the editor is opened as root and you don’t have the same configuration.
I just make /root/.config/nvim a symlink to ~/.config/nvim and running nvim as root gives me all the same settings I’m used to. (I’d rather not run nvim-qt as root though, so in that case sudoedit is useful.)
It doesn’t edit the file directly, it creates a temp file that replaces the file when saving. It means that the editor is run as the user, not as root.
So it opens the file in your editor, since you have read access to it. Then saves your changes to a temp file. Then when you close the editor it does a sudo mv tmpfile readfile?
I checked this by checking the file ownership when running
touch myself
. The file is owned by root.sudo nano myself
also creates a file owned by root.sudoedit myself
bitches at me not to run it in a writable directory.So I ran it in a non-writable directory and the resulting file is still owned by root.
So is the advantage of
sudoedit
preventing a possible escalation of privileges situation?For me personally the advantage is that since the editor is opened by your user, it has all of the same config that I’m used to (such as my souped up Neovim config).
Whereas if you
sudo nvim /path/to/file
then the editor is opened as root and you don’t have the same configuration.That’s a pretty big advantage actually. Thanks!
I just make
/root/.config/nvim
a symlink to~/.config/nvim
and runningnvim
as root gives me all the same settings I’m used to. (I’d rather not runnvim-qt
as root though, so in that casesudoedit
is useful.)Yes, and it also lets me use my neovim config.