6

I've started using sudoedit <file> instead of sudo vim <file>. One of the advantages is that it uses my local ~/.vimrc. However, when using sudo crontab -e, it uses /root/.vimrc instead. Is there a way to make sudo crontab -e use my local ~/.vimrc?

Here is a related question, about using sudoedit with vimdiff. However, substituting crontab -e for vimdiff doesn't work.

Sparhawk
  • 19,941
  • It's related to incomplete and complete using of new user, it means you have to use complete or incomplete in all of items and a good example for using of shell environment is su - looking for same thing in sudo – PersianGulf May 17 '15 at 02:26
  • 1
    @MohsenPahlevanzadeh Sorry, I don't understand what you are saying. There is no new user, and I'm not sure what you mean by "incomplete and complete". – Sparhawk May 17 '15 at 02:30
  • Suppose all of your command OR doesn't use shell enviorment or use shell environment, When some of them use and some of thm don't use , it means incomplete and complete... – PersianGulf May 17 '15 at 02:32

1 Answers1

1

Assuming that you want to be editing root's crontab, sudo must give you root authority. After it does so, crontab will invoke ${VISUAL:-${EDITOR:-vi}} (it'll use $VISUAL unless it doesn't exist; in that case it'll use $EDITOR unless it doesn't exist; in that case it'll use vi).

You have a few possible solutions. They all subvert the security provided by sudo, but you must already be aware of those issues (and be willing to protect your .vimrc) or you wouldn't be using sudoedit in the first place.

The best is probably to add an assignment to the HOME variable on the sudo command line so crontab thinks the HOME directory is different:

sudo HOME=$HOME crontab -e

(That command won't work if there's whitespace in your home directory path!)

Azhrei
  • 341
  • It looks like this might be as good as it gets. However, it's missing out on some of the other advantages of sudoedit. For example admins can restrict users to sudoedit, rather than sudo vim. If they use the latter, they can execute arbitrary commands as root, e.g. :! rm foo. This suffers from similar vulnerabilities. However, in a real world environment, access to root's crontab is just as vulnerable. – Sparhawk May 25 '15 at 02:56