• 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 disable a specific command for a specific user in Linux

by admin

Question: How to prevent a given user from being able to run a specific command.

This technique uses a filesystem access control list (ACL) to prevent unwanted access.

Caution: The sudo facility is not suitable for this purpose. In particular, “subtracting” an executable from the allowed ALL preset does not work as expected.

The example below prevents user john from creating any directories via the mkdir command. The steps are:

1. Find the absolute path to the command to be controlled:

# which mkdir
/bin/mkdir

2. Display the current ACL for that program:

# getfacl /bin/mkdir
# file: bin/mkdir
# owner: root
# group: root
user::rwx
group::r-x
other::r-x

The user, group, and other entries correspond to the traditional file access permissions managed by the chmod command.

3. Add an access control rule for the user john:

# /bin/setfacl -m u:john:--- /bin/mkdir

4. View the updated access control:

# getfacl /bin/mkdir
getfacl: Removing leading '/' from absolute path names
# file: bin/mkdir
# owner: root
# group: root
user::rwx
user:john:---
group::r-x
mask::rwx
other::r-x

5. Test the setting:

# su - john
$ mkdir
-bash: /bin/mkdir: Permission denied

Consider adding an execution watch using the auditctl tool to augment this protection.

How to audit all Commands run on OEL 5,6 using auditd

Filed Under: Linux

Some more articles you might also be interested in …

  1. fprintd-delete: command not found
  2. mkfs Command Examples in Linux
  3. How To Setup mutt in CentOS/RHEL
  4. CentOS / RHEL 7 : How to enable or disable automatic updates (via packagekit)
  5. make: command not found
  6. mt Command Examples in Linux
  7. locate Command Examples in Linux
  8. dockerd Command Examples in Linux
  9. netplan: command not found
  10. How to Tune Btrfs Filesystem for Better Performance

You May Also Like

Primary Sidebar

Recent Posts

  • pw-cat Command Examples in Linux
  • pvs: command not found
  • pulseaudio: command not found
  • pulseaudio Command Examples in Linux

© 2023 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright