

Introduction Not all Linux distributions force a root or other superuser password to be set during installation.

#SUDO SU WITHOUT PASSWORD HOW TO#
Open a new terminal and run sudo whatever, then close it and open another new terminal and run sudo whatever, you will see that sudo asks for password every time. How to Change root Password via sudo Without su Last updated: MaWritten by: Hiks Gerganov Administration passwd We're looking for a DevOps Lead with bash, LAMP/LEMP and CI/CD stack experience: Read More 1. The scenario you are experiencing is caused by the users cached credentials for sudo, which allow sudo to maintain a session and any further sudo command will not prompt for passwords. In this case, the user (for example aaronk) who will switch to another user account (for example postgres) should be in the sudoers file or in the sudo group to be able to invoke the sudo command.

It looks like this: #includedir /etc/sudoers.d This is a sneaky little directive, as it appears to be a commented line upon first glance. Note: As mentioned, you may need to use adm as your admin group name, depending on which version of Ubuntu is being used.Īs I was researching this, I realized that there's a line in the /etc/sudoers file that is not a comment, but a directive that makes any file or folder under the directory /etc/sudoers/* override the contents of /etc/sudoers. You can also add the default AWS ubuntu user to the admin group via this command: sudo usermod ubuntu -g admin Which means: whenever user-a executes sudo -u user-b (or any other variant), let him go without asking for password. (on older versions of ubuntu, you may need to): sudo service sudo restartĮdit: You may have to add the admin group as I don't think it exists by default. Open /etc/sudoers.d/custom and write the following: user-a ALL (user-b:user-b) NOPASSWD:ALL. Then for every user that needs sudo access WITH a password: sudo adduser sudoĪnd for every user that needs sudo access WITH NO password: sudo adduser admin # See sudoers(5) for more information on "#include" directives:
# Members of the admin group may gain root privileges then for every user that needs sudo access WITH a password: sudo adduser# Allow members of group sudo to execute any command # See the man page for details on how to write a sudoers file.ĭefaults secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" # Please consider adding local content in /etc/sudoers.d/ instead of You should now have this: # This file MUST be edited with the 'visudo' command as root. To this line: # Members of the admin group may gain root privilegesĪnd move it under this line: # Allow members of group sudo to execute any command I found that the most straight forward thing to do, in order to easily replicate this behavior across multiple servers, was the following: sudo visudoĬhange this line: # Members of the admin group may gain root privileges
