You are not logged in.

#1 2024-01-11 07:55:39

phoenix324
Member
Registered: 2023-08-23
Posts: 106

[solved] `sudo -e` Vs `sudo -E`, which should be preffered?

My goal was to preserve neovim config `~/.config/neovim` when editing files with sudo.

I read the man page and also https://wiki.archlinux.org/title/sudo#, Also a good read - https://superuser.com/questions/785187/ … er-sudo-vi


From what i understand ->
1. `-E` will preserve all my env vareables, so neovim will be run as root using the config from my home directory.
2. `-e` will make a temp copy of the file with my user premission and open neovim with my home config. Downside is that changes won't be reflected until i save and exit the neovim.

But i am still confused which should be preffered for my usecase and the reasoning behind it.

Last edited by phoenix324 (2024-01-11 09:22:41)

Offline

#2 2024-01-11 08:43:29

just4arch
Member
Registered: 2023-01-07
Posts: 126

Re: [solved] `sudo -e` Vs `sudo -E`, which should be preffered?

Why not sudoedit?

man sudo wrote:

When invoked as sudoedit, the -e option (described below), is implied.

Offline

#3 2024-01-11 09:01:01

mpan
Member
Registered: 2012-08-01
Posts: 1,599
Website

Re: [solved] `sudo -e` Vs `sudo -E`, which should be preffered?

These two options are completely unrelated to each other. There is no preference for one over another.

Only `sudo -e` (or sudoedit) can edit files and does that running as the invoking user.

Your other invocation does not edit any file. It elevates privileges to root, then runs a program with these privileges, while passing your user’s environment variables to that program. It happens, that the program you invoke is a text editor, but this is unrelated to sudo or the `-E` option.

Blanket passing all user’s environment variables to a program executed as another user, in particular root, may have negative implications. For security of the system, and for integrity of both invoking user’s and system. In the first case it may permit unwanted privilege escalation. In the other it may cause pollution or damage to data of either side.


Paperclips in avatars? | Sometimes I seem a bit harsh — don’t get offended too easily!

Offline

#4 2024-01-11 09:22:26

phoenix324
Member
Registered: 2023-08-23
Posts: 106

Re: [solved] `sudo -e` Vs `sudo -E`, which should be preffered?

mpan wrote:

It happens, that the program you invoke is a text editor, but this is unrelated to sudo or the `-E` option.

That's why i got confused which method i should be using as both were in the end editing text.


mpan wrote:

Blanket passing all user’s environment variables to a program executed as another user, in particular root, may have negative implications. For security of the system, and for integrity of both invoking user’s and system. In the first case it may permit unwanted privilege escalation. In the other it may cause pollution or damage to data of either side.

This is what i wanted to know.

Thank you. I will go with `sudo -e`/`sudoedit` for editing files.

Offline

Board footer

Powered by FluxBB