• 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 Restrict su Access to a User Only by PAM in Linux

by admin

In some situation, you need to restrict the su access to:
– only user ‘oracle’ can switch to a particular user (e.g. switch to admin by ‘su – admin’ to maintain system), switching to other users will still fail.
– other users cannot access su.

Modifying the default PAM setting for su can accomplish the goal. Steps below to set up the restriction for su:

1. Create a new group for oracle that is allowed to run su:

# groupadd adminmembers

2. Add users (oracle) to the group:

# usermod -G adminmembers oracle

3. Create the /etc/security/su-adminmembers-access file and add ‘admin’ to it:

# cat /etc/security/su-adminmembers-access 
admin

Make sure /etc/security/su-adminmembers-access is only writable for ‘root’ user and not any other user.

# ls -l /etc/security/su-adminmembers-access
-rw-r--r-- 1 root root 7 Dec 4 12:44 /etc/security/su-adminmembers-access

4. Add following rules to /etc/pam.d/su configuration file:

auth  required    pam_wheel.so use_uid group=adminmembers debug
auth  required    pam_listfile.so item=user sense=allow onerr=fail file=/etc/security/su-adminmembers-access

With above two rules, switching users by su will be restricted to:

  • Only user in group ‘adminmembers’ (e.g. in this case, oracle) can switch to admin by ‘su – admin’ with valid passwd
  • Users in group ‘adminmembers’ can only switch to ‘admin’ by ‘su – admin’, switching to other users still fails
  • Users NOT in group ‘adminmembers’ cannot use ‘su’ to switch users
  • User ‘root’ can still switch to any other users
  • Please remind that above setting may only be considered if you need such a strict su policy. In general, using sudo is recommended to achieve more adaptive switching policies.

Filed Under: CentOS/RHEL 6, CentOS/RHEL 7, Linux

Some more articles you might also be interested in …

  1. jstest: command not found
  2. Anonymous User Fails to Upload File to VSFTP Server
  3. gnome-screenshot Command Examples in Linux
  4. eject: command not found
  5. iperf Command Examples in Linux
  6. ‘Found duplicate PV’ warnings when using LVM with multipath storage in RHEL/CentOS
  7. Understanding OpenSSH Configuration Files
  8. How to Configure an NFSv4-only Client using nfsconf in CentOS/RHEL 8
  9. How to configure DM-Multipath from an iSCSI initiator to an iSCSI target in CentOS / RHEL
  10. How to run “find” command on current directory only and not on sub-directories

You May Also Like

Primary Sidebar

Recent Posts

  • powertop Command Examples in Linux
  • powertop: command not found
  • powerstat: command not found
  • powerstat Command Examples in Linux

© 2023 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright