Sudo: allow command without password

Nearly every Linux distribution these days uses the sudo utility as a way to grant non-privileged users the ability to execute commands as privileged root users. You may have noticed that after entering your sudo password once, you can continue to execute commands without needing to re-enter it for five minutes. We can even extend this convenience by allowing any sudo commands to be executed without a password.

In this tutorial, we will cover the step by step instructions to configure a Linux system to allow the execution of sudo commands without requiring any password. This functionality can be configured for an individual user, a group, or for everyone across the whole system. Follow along with us below to get started.

In this tutorial you will learn:

  • How to allow sudo command without password for a user, group, or all users
Sudo: allow command without password
Sudo: allow command without password
Software Requirements and Linux Command Line Conventions
Category Requirements, Conventions or Software Version Used
System Any Linux distro
Software N/A
Other Privileged access to your Linux system as root or via the sudo command.
Conventions # – requires given linux commands to be executed with root privileges either directly as a root user or by use of sudo command
$ – requires given linux commands to be executed as a regular non-privileged user
WARNING
Disabling the sudo password will make your system very insecure, especially if you choose to disable the password for all users on your system. We recommend only performing this operation on single user systems or in a test environment.

Allow Sudo Command Without Password step by step instructions



Twitter icon Follow LinuxConfig.org on Twitter for the latest tips and tricks about Linux!

  1. Start by opening a command line terminal and editing the /etc/sudoers file. This can be accomplished with the following command:
    $ sudo visudo
    
  2. Scroll down to the bottom of the file, where we will be adding a line.
    Editing the /etc/sudoers configuration file
    Editing the /etc/sudoers configuration file
  3. Add the following line to disable the sudo password for a specific user. In this example, we are disabling the password promot for user linuxconfig.
    linuxconfig ALL=(ALL) NOPASSWD: ALL
    
    Disabling the sudo password for a single user (recommended option)
    Disabling the sudo password for a single user (recommended option)
  4. Another option is to disable the sudo password for all users that belong to a certain group. For example, the sudoers group.
    %sudoers ALL=NOPASSWD: ALL
    
  5. The last option is to disable the sudo password for every user on the system, which is the least secure and least recommended option.
    %sudo ALL=(ALL:ALL) NOPASSWD: ALL
    
  6. When done, save your changes and exit the file. The changes should take effect immediately and there is no need to restart the system. To verify it worked, open a new terminal and try executing some command with sudo.
    $ sudo whoami
    root
    

Closing Thoughts




In this tutorial, we saw how to allow a sudo command to be executed without providing an adminitrator password on a Linux system. Although it is very convenient to never be prompted for your root password, it comes with a high security risk. It is strongly discouraged to perform this operation on a shared system or production server.



Comments and Discussions
Linux Forum