Linux Programmer | RHCE | RHCSA

Search This Blog

Thursday, 27 January 2022

Execute programs with sudo privilleges with non-root users

Sometimes we don't want normal users to provide sudo rights. but we want to run some scripts which can only run with the sudo.

in that case we can set user rights that will run only specific script with sudo privilleges.

You can perform this by three ways.

Method 1:

 
Create file (vim /etc/sudoers.d/iosys) and add below lines in created file.
 

username ALL=NOPASSWD:/command/to/execute
username ALL=NOPASSWD:/command/to/execute 

Note: Change username accordingly.

Method 2: 


Open below configuration file, and made provided changes into it.

nano /etc/sudoers

Edit it with below lines,


# User privilege specification
 

root    ALL=(ALL:ALL) ALL

ALL ALL =(root) NOPASSWD:/command/to/execute
# Members of the admin group may gain root privileges
%admin ALL=(ALL) ALL
# Allow members of group sudo to execute any command
%sudo   ALL=(ALL:ALL) ALL
%sudo   ALL=NOPASSWD:/command/to/execute 




No comments:

Post a Comment

SSH not working with password after upgrade ubuntu 22.04 or above

In recent upgrade of ubuntu 22.04 and above we are not able to login server with SSH password. but when we try to login with key then it all...