Why did my default crontab editor change?
Andrew Henderson
I have an Amazon Linux instance I have been using for years as a web server. It's been awhile since I've logged in. Today I logged in and noticed the default crontab editor has been changed from nano to vi.
I have looked, and for the life of me I can't figure out how to change it back to nano, which begs the question - how did it get changed universally in the first place? What might have caused this?
My two questions are:
- How could this have happened?
- How can I change it back (permanently)?
I don't see anything in the logs or command history to help, but I'll note that I installed the new/latest acme.sh updater for Let's Encrypt a couple months ago, and it did install a cronjob for the root user (of which I was aware).
I can change the default editor back by either setting the .selected_editor file/value, or by export EDITOR=/bin/nano, but this seems to only address the issue for the current user (so, if I crontab -e -u <otheruse>, it edits as vi again), but I want the DEFAULT editor changed for crontab, so I always get the same editor, regardless of what user I'm working as.
1 Answer
The usual order for editors on Unix systems is as follows:
- The value of the environment variable
VISUAL, if the user has a TTY and the terminal is not dumb (i.e.,TERMis set to something other thandumb). - The value of the environment variable
EDITOR. - 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_resetNote that, as mentioned, that has security considerations which you should read about in the manual page.
1