Home » Questions » Computers [ Ask a new question ]

VIM: "sudo vim bad_idea"?

VIM: "sudo vim bad_idea"?

An irc-user in #Vim urged me not to use Sudo with Vim like:

Asked by: Guest | Views: 342
Total answers/comments: 5
Guest [Entry]

I fall under the first category: sudo vim /var/www/html/some_file is a bad idea; it allows shell escapes that aren't logged. Instead, use sudoedit /var/www/html/some_file; that has the same effect.
Guest [Entry]

"vim allows users to execute arbitrary shell commands, therefore many system admins do not allow vim to be used with sudo.

rvim is included with vim. It is a restricted vim, that does not allow shell commands. (Or allow you to suspend vim, for the same reasons.)

Whether you need to go to those extremes on your own box is debatable."
Guest [Entry]

"Running sudo vim won't change the $HOME directory, so you will be running Vim with root permissions, but $HOME is still pointing to your normal user.

If this is the first time you are running Vim, it may happen that ~/.viminfo file is created inside your normal user directory, but with root permissions."
Guest [Entry]

"IF THIS IS YOUR OWN COMPUTER... I see no reason why you can't use 'sudo vim', other than the edge case that Denilson noted - that it might create your ~/.viminfo owned by root.

If not - if a systems administrator is restricting what you can and can't do - per ""man sudo"": ""on most systems it is possible to prevent shell escapes with sudo's noexec functionality. See the sudoers(5) manual for details.""

So in this case, if your sysadmin is concerned about the potential of you running subshells as root from within vim, they can use the noexec capability. But... back to the initial case - if this is YOUR computer, I think you're pretty darn safe running 'sudo vim'."
Guest [Entry]

"A reference to balpha's reply about groups:

Howto: Linux Add User To Group"