Setting a text editor for visudo

As you know, the recommended way for editing the/etc/sudoers file is with visudo. Visudo opens the /etc/sudoers file with the default text editor, and warns you if you save code with errors.

Visudo reads the SUDO_EDITOR, VISUAL and EDITOR variables, in this order, when choosing the text editor for editing /etc/sudoers. So, you can set nano, for example as your visudo editor and use vim as your default text editor.

Examples for setting popular text editors for visudo:

1. Vim: /usr/bin/vim

$ export SUDO_EDITOR="/usr/bin/vim"

Making the setting persistent:

$ echo 'SUDO_EDITOR="/usr/bin/vim"' >> ~/.bashrc

2. Nano: /usr/bin/nano

$ export SUDO_EDITOR="/usr/bin/nano"

Making the setting persistent:

$ echo 'SUDO_EDITOR="/usr/bin/nano"' >> ~/.bashrc

3. JOE: /usr/bin/joe

$ export SUDO_EDITOR="/usr/bin/joe"

Making the setting persistent:

$ echo 'SUDO_EDITOR="/usr/bin/joe"' >> ~/.bashrc

4. Emacs: /usr/bin/emacs

$ export SUDO_EDITOR="/usr/bin/emacs"

Making the setting persistent:

$ echo 'SUDO_EDITOR="/usr/bin/emacs"' >> ~/.bashrc

If you are using zsh, replace ~/.bashrc with ~/.zshrc and for ksh replace ~/.bashrc with ~/.kshrc.


Tagged with: , , , , , , , , , , , , ,
Posted in The Linux and Unix Articles!

Leave a Reply

Your email address will not be published. Required fields are marked *




Subscribe to get the latest Linux news and how to guides directly on your e-mail!