Search code examples
linuxredhat

How to set specific user can run certain root command in redhat


i want to ask for a specific user to use certain root commands in redhat?

my server run redhat OS 7.6. i dont have any idea how to set a user that can run certain commands from root.

let say i have one user id name MY_CIT, so MY_CIT can run certain commands for example to create print queue #lpadmin -p printer -v socket://printer:9100 -E

so MY_CIT no need root access to trigger the command.

Anyone experience on this? kindly help. thanks


Solution

  • Run command with a root privilege:

    sudo visudo
    

    It opens file /etc/sudoers for edit.
    Add this line at the end of the file (and after keep one blank line):

    MY_CIT ALL = NOPASSWD: /usr/sbin/lpadmin
    

    where:

    MY_CIT - name of your user
    /usr/sbin/lpadmin - path to executible file. Note please that in your distro path can be different. You can check this with command whereis lpadmin.

    After user can run command lpadmin with arguments with sudo without password:

    sudo lpadmin ...