How to find out what linux capabilities a process requires to work?


I am in a difficult situation where I don’t know what linux capabilities a process requires to work.
What is the best way, or any way to find out what cap is required?

The only thing I can think of right now is using capsh and drop all caps on a process. The process then fails and I start to add caps (by removing –drop=CAP_XZY) until it works.

Any better suggestions?


Based on recent libcap2 update

1: (Short option): getpcaps


From here:

getpcaps displays the capabilities on the processes indicated by the
pid value(s) given on the command line.


$ getpcaps <PID>
PID: = cap_chown,cap_dac_override,cap_fowner,cap_fsetid,cap_kill,cap_setgid,cap_setuid,cap_setpcap,cap_net_raw,cap_sys_chroot,cap_mknod,cap_audit_write,cap_setfcap+i

2: (A bit longer option): /proc status and capsh


proc is a process information pseudo-filesystem or in other words – a directory where you can view information on all processes.

About capsh:

Linux capability support and use can be explored and constrained with
this tool. This tool provides a handy wrapper for certain types of
capability testing and environment creation.
It also provides
some debugging features useful for summarizing capability state.


$ cat /proc/<PID>/status | grep Cap

And you’ll get (on most systems):

CapInh: 00000000a80425fb (Inherited capabilities)
CapPrm: 0000000000000000 (Permitted capabilities)
CapEff: 0000000000000000 (Effective capabilities)
CapBnd: 00000000a80425fb (Bounding set)
CapAmb: 000000000000000  (Ambient capabilities set)

Use the capsh utility to decode from hexadecimal numbers into the capabilities name:

capsh --decode=00000000a80425fb

(*) You can download capsh with: sudo apt-get install git libpcap-dev.

Answered By – RtmY

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published