[LINUX] Problems with `visudo` not working on Ubuntu 18.04 and its workaround

Searching for "no sudo password" etc., I found several ways to edit / etc / sudoers with visudo, but it didn't work in my environment (Ubuntu 18.04). A note of the underlying situation and solution.

problem

I edited / etc / sudoers with visudo and tried to do sudo only for certain commands without a password. But it doesn't work.

Specifically, for example

$ sudo visudo

/etc/sudoers


...

%sudo  ALL=(ALL:ALL) ALL
kobalt ALL=(ALL) NOPASSWD: /usr/bin/whoami

...

Even as

$ sudo whoami
[sudo] password for kobalt:

I will be asked for a password.

solution

Instead of using visudo, create a file under /etc/sudoers.d/ and describe the settings you want to add to it.

$ cd /etc/sudoers.d
$ sudo vim free_whoami

/etc/sudoers.d/free_whoami


kobalt ALL=(ALL) NOPASSWD: /usr/bin/whoami

Then

$ sudo whoami
root  #No password required

Finally

By the way, I ran into this problem during the process of making the key remapper called xkeysnail start up automatically at startup.

Now it seems that you can move the cursor on Ubuntu without moving from the home position.

Recommended Posts

Problems with `visudo` not working on Ubuntu 18.04 and its workaround
Ubuntu 20.04 on raspberry pi 4 with OpenCV and use with python
Dealing with pip and related installation errors on Ubuntu 18.04
Install and run dropbox on Ubuntu 20.04
Install OpenCV and Chainer on Ubuntu
Install CUDA 8.0 and Chainer on Ubuntu 16.04
Draw Japanese with matplotlib on Ubuntu
Mount S3 on Ubuntu with goofys
Install fabric on Ubuntu and try
Build Python3 and OpenCV environment on Ubuntu 18.04
Python virtual environment and packages on Ubuntu
A memo with Python2.7 and Python3 on CentOS
Mount and format Disk on Ubuntu on GCP.
Working with sensors on Mathematica on Raspberry Pi
Install Puppet Master and Client on Ubuntu 16.04
Install pyenv and Python 3.6.8 on Ubuntu 18.04 LTS
Working with GPS on Raspberry Pi 3 Python