Open Another User’s Crontab in Preferred Editor – How to

croneditors

I work in a team. We have a CentOS Linux machine. There's a user there called www. We run cron jobs as that user, i.e. I can type sudo -u www crontab -e to see/edit the crontab, and my teammates do the same. However, I like to use nano as my editor, but the crontab opens in vim, because that's the EDITOR for the www user.

Is there a way I can get the crontab to open in nano, without changing the EDITOR setting for the www user? (e.g. via the addition of some additional command line parameter?) My teammates will continue to expect vim to open when they themselves run sudo -u www crontab -e.

Best Answer

You can specify the EDITOR variable as an argument to sudo:

sudo -u www EDITOR=nano crontab -e
Related Question