Ubuntu set up sudo without password

Step 1: Use the su command to switch to the root user

Enter the following command in the terminal:

sudo su -

Enter the password of the current user to switch to the root user.


Step 2: Use the following command to modify the sudoers file permissions

Enter the following command in the terminal:

chmod 777 /etc/sudoers

This will allow the user to write-modify the sudoers file.


Step 3: Edit the sudoers file

Enter the following command in the terminal:

visudo

This will open the sudoers file for editing with the vi editor. Note, do not edit the sudoers file directly using the vi command, as this may cause problems with the file format.

Add the following lines at the end of the file:

user ALL=(ALL:ALL) NOPASSWD:ALL

Please note that user needs to be replaced with the username that you want to set sudo password-free.

Save and exit the file. In the vi editor, you can save and exit with the following commands:

:wq

Step 4: Restart to make the configuration take effect

Enter the following command in the terminal and restart for the configuration to take effect:

sudo reboot

Now, the user user will no longer need to enter a password to execute the sudo command with administrator privileges.

⚠️It should be noted that you must be careful when modifying the sudoers file. Improper modification may cause the system to fail to start. If you are not sure how to modify the sudoers file, it is recommended to back up the original file first, or ask an experienced administrator to assist in the operation.

Guess you like

Origin blog.csdn.net/LGL979643718/article/details/129462180