• Home
  • Linux
  • Ubuntu
  • Debian
  • CentOS
  • Linux Commands
  • About Us
  • Donate
TecNStuff
Menu
  • Home
  • Linux
  • Ubuntu
  • Debian
  • CentOS
  • Linux Commands
  • About Us
  • Donate

How to Run Sudo Command Without Password

Written by Admin, Updated On August 8, 2020
sudo, terminal
Run Sudo Command Without Password

The sudo (sudouser do) command is a tool in Linux systems, used to run commands or programs as another user, by default as root user. If you doing administration task then you need to use sudo frequently. This article show you how to run sudo command without entering password.

To grant the sudo access to a user you need to add the user to the sudo group defined in sudoers file. In Debian, Ubuntu other Debian based distributions, members of the group sudo are granted with sudo privileges while on RedHat based distributions such as CentOS and Fedora, the sudo group is wheel.

The members of this sudo or wheel group will be asked to enter the password while using sudo command. It’s like an extra layer of security before granting sudo privileges. But sometimes, it’s required to omit this layer and allow to certain user to work with sudo without being asked for the password.

Adding User to the Sudoers File#

The information about user and group privileges are store in sudoers file. You should edit the sudoers file to configure the sudo access or you can add the separate configuration file to the /etc/sudoers.d directory. After that you must include this directory in sudoer file.

Open the /etc/sudoers file with the visudo command:

Always use visudo while making changes to sudoer file. This command checks the file after editing, and if there is a syntax error it will not save the changes.

By default, the visudo command opens the /etc/sudoers file with the vim text editor. If you are not familiar with vim editor you can use another text editor. You can change to nano text editor by typing:

sudo EDITOR=nano visudo

Add the following lines to the end of the file which will allow the user tecnstuff to run any command with sudo without asking the password:

tecnstuff ALL=(ALL) NOPASSWD:ALL

Note : You must change the tecnstuff with your username.

You also can allow specific commands without entering password by specifying the commands after NOPASSWD keyword.

For example, if you want to just allow the mkdir and mv commands:

tecnstuff ALL=(ALL) NOPASSWD:/bin/mkdir,/bin/mv

Save the files and quit the text editor.

Using /etc/sudoers.d#

If you would like to manage the sudo access in a uniform way, you can make separate file with the authorization rules in the /etc/sudoers.d directory.

Create a file by opening your text editor:

sudo nano /etc/sudoers.d/tecnstuff

You can set any name for file, but it is best practice to use same name as username.

Add the same rule as you would add to the sudoers file:

tecnstuff ALL=(ALL) NOPASSWD:ALL

At last, save the file and quit the editor.

Conclusion#

You have successfully learned how to configure the user to run sudo command without entering password. This is useful when you have scripts which execute administration task automatically.

If you have any questions or suggestion, please leave a comment below.

If our content helps you, please consider buying us a coffee

Thank you for your support.

Share On
Share on Facebook
Share on Twitter
Share on Reddit
Share on Tumblr
 Previous Article How to Add User to Group in Linux Systems
Next Article   Bash Source Command

Related Posts

  • How to Install SSH Keys on Ubuntu 22.04

    How to Set up SSH Keys on Ubuntu 22.04

    January 7, 2023
  • How to Install Fail2ban on Ubuntu 22.04

    How to Install and Configure Fail2ban on Ubuntu 22.04

    December 5, 2022
  • How to Enable SSH on Ubuntu 22.04

    How to Enable SSH on Ubuntu 22.04

    December 1, 2022

Leave a Reply Cancel reply

DigitalOcean Referral Badge

Popular Posts

  • How to Install Microsoft Edge Browser on Ubuntu 22.04
    How to Install Microsoft Edge Browser on Ubuntu 22.04 March 14, 2023
  • How to Install Ruby on Ubuntu 22.04 LTS
    How to Install Ruby on Ubuntu 22.04 LTS February 27, 2023
  • How to Install LEMP Stack on Ubuntu 22.04
    How to Install LEMP Stack on Ubuntu 22.04 March 18, 2023
  • How to Install Set Up Apache Virtual Hosts on Ubuntu 22.04
    How to Set Up Apache Virtual Hosts on Ubuntu 22.04 March 2, 2023
  • How to Install MariaDB on Debian 11 Bullseye
    How to Install MariaDB on Debian 11 Bullseye March 8, 2023
© 2020 TecNStuff All rights reserved. This website is using and storing cookies on your browser. By using this website you agree our Privacy Policy.  Follow us -  Twitter | Facebook