Course contentsShow
← Linux
Lesson 867 of 1,8198. User Management and Pluggable Authentication ModulesFree lesson

Managing User-specific Capabilities

You will strip excess privileges from users by leveraging Linux kernel capabilities instead of sudo.

In this lesson, you will learn how to replace broad sudo privileges by assigning specific, granular Linux kernel capabilities directly to user-space binaries or processes.

Beyond the "All-or-Nothing" Approach

Traditionally, we grant administrative power by adding a user to the wheel or sudo group. However, this is an "all-or-nothing" approach: a user with sudo access can modify any part of the system. In many production environments, we only need a user to perform one specific privileged action, such as binding to a low-numbered network port or setting the system clock. Linux capabilities allow us to break the monolithic root privilege into smaller, manageable chunks.

Applying Capabilities to Binaries

Instead of giving a user sudo access to run a network utility, you can grant that specific utility the CAP_NET_BIND_SERVICE capability. When a file has this capability bit set, the kernel allows the process to execute that specific privileged task, even if the user running it is unprivileged.

To assign a capability to an executable, use the setcap command. For example, to allow a custom network server to bind to port 80 without needing root access, you would run:

# Granting the ability to bind to privileged ports
sudo setcap 'cap_net_bind_service=+ep' /usr/local/bin/my-web-server

Why This Improves Security

When you grant CAP_NET_BIND_SERVICE to a specific binary, you aren't granting the user permission to edit /etc/shadow, install packages, or reboot the machine. If the application is compromised, the attacker remains trapped within the boundaries of those specific capabilities. This minimizes the "blast radius" of a security breach.

You can view the capabilities currently assigned to a binary using getcap:

getcap /usr/local/bin/my-web-server
# Output: /usr/local/bin/my-web-server = cap_net_bind_service+ep

By shifting from sudo to kernel capabilities, you adhere to the principle of least privilege, ensuring that your users and their applications have only the absolute minimum permissions required to function.

Key Takeaway: By using Linux kernel capabilities, you can surgically grant specific privileged permissions to binaries, effectively eliminating the need for excessive sudo access and hardening your system against privilege escalation.