Skip password with sudo command

To execute the systemctl restart bluetooth command without entering a password on Ubuntu Linux 20.04, you can set up a specific sudoers configuration. This allows your user account to execute this specific command without being prompted for a password.

Follow these steps:

Open the sudoers file using the visudo command. It's essential to use visudo to edit the sudoers file to prevent syntax errors:

sudo visudo

Scroll down or navigate to the bottom of the file and add the following line:

your_username ALL=(ALL) NOPASSWD: /bin/systemctl restart bluetooth

Replace your_username with your actual username on the system. This line grants your user account permission to run the specified command without a password prompt.

Save the changes and close the editor. In visudo, you can save by pressing Ctrl + X, then Y to confirm changes, and Enter to exit.

Now, when you run sudo systemctl restart bluetooth with the specified username, it shouldn't prompt for a password. Remember to be cautious when modifying sudoers, as incorrect settings might impact system security. Always follow best practices and ensure you're aware of the security implications.

Adding users to sudoers

If there is a sudo group, you can do the following:

$sudo adduser <username> sudo

This works because /etc/sudoers is pre-configured to grant permissions to all members of this group (You should not have to make any changes to this):
# Allow members of group sudo to execute any command
%sudo   ALL=(ALL:ALL) ALL

Otherwise, you can add the user directly

$nano /etc/sudoers

add the following to the end of the file, and save:
username ALL=(ALL) ALL

Sudo for web_app

From: Schumacher, Mike (HAL)
Sent: Friday, March 02, 2012 10:26 AM
To: Bojja, Sridhar (HAL Contractor)
Cc: Augustine, Anila (HAL); Hofsetz, Therron (HAL); Bobroff, Harold (HAL)
Subject: sudo webapp on haldevjbs01

Sridhar,

I found the issues for using sudo to the webapp account. You need to run the following command in order to become the webapp user.
"sudo -u webapp /bin/bash" then enter your passwd. If you are in your home directory you will get a permissions error like the one below.

[szb@haldevjbs01 ~]$ sudo -u webapp /bin/bash
bash: /home/szb/.bashrc: Permission denied

That is because the user webapp doesn't have write permissions in your home directory but you are now user webapp. Just cd out of your home directory. If you want to make sure your now webapp type "id" on the command line.

Thanks-

Mike Schumacher