1. Set sudo to not require a password
Sometimes we only need to execute a command with root privileges and also su to root, is it inconvenient? You can use sudo instead. By default, the newly created user is not in the sudo group. You need to edit the /etc/sudoers file to add the user. This file can only use the visudo command.
1) First, you need to switch to root, su - (note that there is - , this is different from su, when you use the command "su", you just switch to root, but you don't pass the root environment variable, it is still used at present environment variables, use the "su -" command to bring the environment variables together, just like logging in with root)
2) Then visudo or vi /etc/sudoers, visudo is the same as vi, because some people may not be familiar with vi, so briefly explain the steps
Move the cursor to the next line of root ALL=(ALL) ALL, press a, enter append mode, enter
your_user_name ALL=(ALL) ALL
Then press Esc, then enter :w to save the file, and then :q to quit
This will add yourself to the sudo group, and you can use the sudo command.
3) The sodo password you just entered expires after 5 minutes by default, and you need to re-enter the password next time for sudo. If you feel that it is troublesome to enter the password during sudo, replace the previous input with the following:
your_user_name ALL=(ALL) NOPASSWD: ALL
As for security issues, for general individual users, I think this is fine.
4) If you want to set only certain commands to sudo, your_user_name ALL= (root) NOPASSWD: /sbin/mount, (root) NOPASSWD: /bin/umount, (root) NOPASSWD: /mnt/mount, (root) NOPASSWD: /bin/rm, (root) NOPASSWD: /usr/bin/make, (root) NOPASSWD: /bin/ln, (root) NOPASSWD: /bin/sh, (root) NOPASSWD: /bin/mv, ( root) NOPASSWD: /bin/chown, (root) NOPASSWD: /bin/chgrp, (root) NOPASSWD: /bin/cp, (root) NOPASSWD: /bin/chmod
Note: Sometimes you set the user to nopasswd, but it does not work. The reason is that it is overwritten by the later group setting. You need to change the group setting to nopasswd.
joe ALL=(ALL) NOPASSWD: ALL
refer to:
1) Switch to root authority;
2) Create a group as wheel, and the command is groupadd wheel;
3) Add the user to the wheel group, and the command is usermod -G wheel joe;
4) Modify the su configuration file /etc/pam.d/su and add the following items:
auth required pam_wheel.so group=wheel
# Uncomment this if you want wheel members to be able to
# su without a password .
auth sufficient pam_wheel.so trust use_uid
At this point you can use commands such as the following without entering a password: su joe -c command.
sudo -i
sudo passwd root
disable by below:
sudo passwd -dl root
refer to:
o(∩_∩)o... Haha, finished!