Why did my default crontab editor change?

Solution 1:

The usual order for editors on Unix systems is as follows:

  1. The value of the environment variable VISUAL, if the user has a TTY and the terminal is not dumb (i.e., TERM is set to something other than dumb).
  2. The value of the environment variable EDITOR.
  3. The default editor, vi.

Some systems, such as Debian, change this order slightly, usually by invoking a tool such as sensible-editor (from sensible-utils) to consider additional options between steps 2 and 3. However, it doesn't appear that the current version of Amazon Linux uses this approach from my testing with a container.

If you're using a terminal editor like Nano, you probably just want to set VISUAL to nano.

However, as you've noticed, this doesn't work in some cases with sudo because it clears the environment by default, possibly excepting some variables such as TERM. This is for security reasons, but not all systems have enabled this option by default, and it's possible that an upgrade caused this option to be set when it wasn't before. You can use sudo -E to not clear the environment, either manually or through an alias, or you can run sudo visudo and remove a line like this one:

Defaults    env_reset

Note that, as mentioned, that has security considerations which you should read about in the manual page.