Search code examples
linuxvimsudo

What is the difference between `sudoedit` and `sudo vim`?


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.


Solution

  • 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.