Crontab – How to Change Default Crontab Editor

crondefault-programstext-editor

I am trying to change the default editor from nano to vim.

I have run the following commands:

sudo update-alternatives --config editor

and

update-alternatives --config editor

Both now output:

  Selection    Path                Priority   Status
------------------------------------------------------------
  0            /bin/nano            40        auto mode
  1            /bin/ed             -100       manual mode
  2            /bin/nano            40        manual mode
* 3            /usr/bin/vim.basic   30        manual mode
  4            /usr/bin/vim.tiny    10        manual mode

I have restarted my ssh session and restarted sshd but crontab -e still opens in nano

What else do I need to do?

Best Answer

Try your ssh session followed by

export EDITOR=vim

or possibly

export EDITOR=/usr/bin/vim.basic

The format of setting of the EDITOR variable depends on which shell you are using.

In Ubuntu you can set the EDITOR environment variable on logon by adding the above to the ~/.profile

Your SSH session will read a similar file (if it exists) on the remote host called ~/.ssh/environment. This has to be specifically defined by the ssh daemon config. See man sshd_config and look for PermitUserEnvironment for more details.