Linux/Ubuntu sudo does not need to enter a password

Source: Internet
Author: User

Generally, we do not log on as root, but we need to use root permission when executing some commands. We usually use "sudo command" to execute commands. Because ubuntu is used, sudo is often used, and when sudo is used, a password is required, so I am looking for a method that does not enter a password for sudo. A few times ago, I googled it and it was easy to find a method, but I didn't understand it enough. Today, I carefully studied the/etc/sudoers file, we are very clear about how to implement our own needs. The information I see on the Internet is often unclear, so I sorted it out according to my own needs.
Assume that my username is Jay (which belongs to the admin group) and sudo does not need a password as follows.
Run the command: sudo cmddo or sudo VI/etc/sudoers. If VI is used for editing, remember to use "WQ! "Force save. Otherwise, the system will prompt that read-only files cannot be saved.
The/etc/sudoers file will be edited. By default, we will see a sentence "% admin all = (all) All", that is, allow the Admin group to execute all commands on all hosts, of course passwd is required.
1. If you want to replace all users in the admin group with sudo without a password, you can change this line to "% admin all = (all) nopasswd: nopasswd all.
2. If you only want to make the Jay user sudo not need a password, you can add a line like "Jay all = nopasswd: All.
3. If you want jay user sudo to execute several commands without a password, you can write "Jay all = nopasswd:/usr/bin/ABC. Sh,/usr/sbin/adduser"
4. For more configuration methods, Run "Man sudoers" to see the help documentation.
Note: One of my own configurations does not take effect. I have to find the reason and write it here.
I added a line like "Jay all = nopasswd: All", but Jay still needs to enter the password when executing sudo. Why?
Originally, before the "% admin all = (all) All" group policy, the group configuration that follows replaced the previous configuration, and Jay belongs to the admin group, the password is required.
In this case, you only need to comment out the % admin line. OK! Then it takes effect immediately. The system may read/etc/sudoers during sudo execution, so it takes effect immediately.

In addition, a/etc/sudoers configuration for a company server is included:
Defaults env_reset
Defaults syslog = auth
Defaults log_year, logfile =/var/log/sudo. Log
User_alias abc = ABC
Cmnd_alias default =/bin/*,/sbin/ldconfig,/sbin/ifconfig,/usr/sbin/useradd,/usr/sbin/userdel,/bin/RPM, /usr/bin/yum,/sbin/service,/sbin/chkconfig, sudoedit/etc/rc. local, sudoedit/etc/hosts, sudoedit/etc/lD. so. conf,/bin/mount, sudoedit/etc/exports,/usr/bin/passwd [! -] *,! /Usr/bin/passwd root,/bin/su -[! -] *,! /Bin/su-root ,! /Bin/su root,/bin/bash,/usr/sbin/dmidecode,/usr/sbin/lsof,/usr/bin/du,/usr/bin/python, /usr/sbin/xm, sudoedit/etc/profile, sudoedit/etc/bashrc,/usr/bin/make, sudoedit/etc/security/limits. conf,/etc/init. d/*,/usr/bin/Ruby
ABC all = (all) nopasswd: Default
From: http://renyongjie668.blog.163.com/blog/static/1600531201066102017514/

By modifying/etc/sudoers
Sudo VI/etc/sudoers
Put the last line in/etc/sudoers
% Admin all = (all)
Change
% Admin all = (all) nopasswd: All
Then, force the WQ to be saved.

The above is not accurate. Pay attention to the following points.

Edit the/etc/sudoers file and use the "superuser terminal" instead of the common terminal. Click "Super User Terminal" and Right-click "edit menu" to add it.

Use WQ after editing! Instead of exiting WQ

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.