disable password prompt for sudo in ubuntu

After using ubuntu Linux in my xiaomi laptop for months, I find the password prompt really annoying when I try to switch to root account by running the command ‘sudo su -‘. After checking the manual page of ‘sudoers’, I find that the below configuration removes the password prompt.

First, run the below command:

visudo -f /etc/sudoers.d/xiaoliang

let’s assume ‘xiaoliang’ is the non-root Linux account.

Note: in my ubuntu distribution, it requires that the filename should not contain a dot character. For example, ‘xiaoliang.conf’ won’t work as expected.

Next, input the below configuration in the editor

xiaoliang ALL = (root) NOPASSWD: /usr/bin/su

After saving the configuration, we can have a try by running the command ‘sudo su -‘. Now the password prompt disappear.