Set su and sudo to not require a password

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

%admin ALL=(ALL) NOPASSWD: ALL

 

refer to: 

http://blog.163.com/love-love-l/blog/static/21078304201071232234518/

 

 

Second, set su to not require a password
If you do not need to enter a password for a user's su command, you need to modify the following:

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.
 
Three ubuntu enable root
sudo -i
sudo passwd root

disable by below:
sudo passwd -dl root

 

refer to:

 

http://cosminswiki.com/index.php/How_to_let_users_su_without_password
http://ag-up.com/?p=457

 

 

 

 

 

o(∩_∩)o... Haha, finished!

 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326992391&siteId=291194637