What is the difference between sudo vim /etc/services
and sudoedit /etc/services
? I tried to edit the /etc/services
file in linux. sudoedit
is allowing to edit, but sudo vim
is not allowing to edit.
2 Answers
sudoedit
specifies sudo
with the -e
option. From the man page:
-e The -e (edit) option indicates that, instead of running a command, the
user wishes to edit one or more files. In lieu of a command, the string
"sudoedit" is used when consulting the security policy. If the user is
authorized by the policy, the following steps are taken.
Therefore, it allows the system administrator to only allow sudo rights for editing certain files, not specific commands or all files in general. It allows the administrator to control which files a user (or groups of users) can edit with elevated privileges.
What's more, the user can still use his/her preferred editor, not one that is specified by the administrator. It also runs this editor as the user itself, meaning that any options or commands specified in a .vimrc
by the user for example will apply.
sudo vim /etc/services
is telling the shell to use vim editor in superuser privilege to edit the file given.
Whereas, sudoedit /etc/services
is telling the shell to use whatever editor is stored in the EDITOR environmental variable to edit the file using super user privileges.
-
1Ya .. this is also correct.. I checked by setting the
EDITOR
variable. After setting theEDITOR
variable tovim
, I can see the file is opened invim
otherwise it is opened invi
.– NadarajFeb 28, 2014 at 4:03
sudoedit
allows you tosudo
as another user.sudoedit
creates a temporary copy of the file you're editing that is owned by the normal user (not the root user), and save the original file when you exit the editor. Since, the editor is run as a normal user when you edit the temporary copy,.vimrc
is loaded normally and you get to keep the syntax highlighting and other vim plugins (which shouldn't be the case if you do asudo vim
).