Sirius
Sirius

目录

目录

更改sudo的editor

目录

ubuntu的默认编译器为nano,当一个命令,如’sudo visudo’时,就会弹出nano编辑器。

对于习惯vim的用户来说,得先来修改它,方法如下:

sudo update-alternatives --config editor

选择vim.basic选项或者nvim选项,回车即可。

此时再次打开时已经是vim编辑器。

其他发行版可以参靠archwiki

The default editor for visudo is vi. The  sudo package is compiled with --with-env-editor and honors the use of the SUDO_EDITORVISUAL and EDITOR variables. EDITOR is not used when VISUAL is set.

To establish  nano as the visudo editor for the duration of the current shell session, export EDITOR=nano; to use a different editor just once simply set the variable before calling visudo:

# EDITOR=nano visudo

Alternatively you may edit a copy of the /etc/sudoers file and check it using visudo -c _/copy/of/sudoers_. This might come in handy in case you want to circumvent locking the file with visudo.

To change the editor permanently, see  Environment variables#Per user. To change the editor of choice permanently system-wide only for visudo, add the following to /etc/sudoers (assuming  nano is your preferred editor):

# Reset environment by default
Defaults      env_reset
# Set default EDITOR to restricted version of nano, and do not allow visudo to use EDITOR/VISUAL.
Defaults      editor=/usr/bin/rnano, !env_editor

相关内容

Linux下 Bash 向内核写日志, 写dmesg可以看的日志
Linux下向系统写日志, 写journalctl可以看的日志