• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer navigation

The Geek Diary

  • OS
    • Linux
    • CentOS/RHEL
    • Solaris
    • Oracle Linux
    • VCS
  • Interview Questions
  • Database
    • oracle
    • oracle 12c
    • ASM
    • mysql
    • MariaDB
  • DevOps
    • Docker
    • Shell Scripting
  • Big Data
    • Hadoop
    • Cloudera
    • Hortonworks HDP

How to use sudo to allow a non-root user run a particular command

by admin

With the help of sudo, you can give access to a non-root user to run a root only command. Here is a short howto to provide the non-root user the access to a root only command. The command access that we will give to a user named “john” will be “/sbin/poweroff”.

Giving sudo access to a command

1. open the /etc/sudoers file. It is recommende to open this file using the visudo command.

# visudo

2. Add the following lines at the end. (though can be added anywhere in the file)

User_Alias ADMINS = john                      --> define which user can run the root only commands
Cmnd_Alias POWEROFF = /sbin/poweroff          --> define which command
ADMINS     ALL=POWEROFF                       --> bind the command with the user

3. Now login with the user john and execute the command :

$ sudo /sbin/poweroff

For the first time, it should ask the john’s password. This should power off the system without asking for the root user credentials.

Filed Under: Linux

Some more articles you might also be interested in …

  1. a2dissite Command Examples in Linux
  2. join Command Examples in Linux
  3. How to troubleshoot iSCSI issues in CentOS / RHEL 6,7
  4. XFS error: Unable to mount filesystem With Noacl Permission in CentOS/RHEL 7
  5. fuser Command Examples in Linux
  6. showmount Command Examples in Linux
  7. flashrom Command Examples in Linux
  8. Getting “parsing errors” When Running ‘yum repolist’
  9. update-alternatives: command not found
  10. atool: command not found

You May Also Like

Primary Sidebar

Recent Posts

  • ncat Command Examples in Linux
  • ncat: command not found
  • nautilus Command Examples in Linux
  • namei: command not found

© 2023 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright