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

The Geek Diary

  • OS
    • Linux
    • CentOS/RHEL
    • VCS
  • Interview Questions
  • Database
    • 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. brittany: Pretty-print Haskell source files
  2. Understanding /etc/hosts file in Linux
  3. nc: command not found
  4. ddcutil Command Examples in Linux
  5. logsave Command Examples in Linux
  6. How to enable md5 Hashing in Linux
  7. lolcat Command Examples in Linux
  8. How to uninstall neovim from Ubuntu
  9. uptime: command not found
  10. Understanding How an Email System Works

You May Also Like

Primary Sidebar

Recent Posts

  • Vanilla OS 2 Released: A New Era for Linux Enthusiasts
  • mk Command Examples
  • mixxx Command Examples
  • mix Command Examples

© 2025 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright