31

An answer to the question "Allowing a regular user to listen to a port below 1024", specified giving an executable additional permissions using setcap such that the program could bind to ports smaller than 1024:

setcap 'cap_net_bind_service=+ep' /path/to/program

What is the correct way to undo these permissions?

Matthias Braun
  • 7,797
  • 7
  • 45
  • 54
user2943160
  • 537
  • 2
  • 5
  • 10

2 Answers2

36

To remove capabilities from a file use the -r flag

setcap -r /path/to/program

This will result in the program having no capabilities.

Stephen Harris
  • 42,369
  • 5
  • 94
  • 123
22

What @stephen-harris posted is right. But it removes all capabilities added to the program in one shot. To remove a specific capability, this should work (following the example in the question):

setcap 'cap_net_bind_service=-ep' /path/to/program

Notice the '-' sign. You can verify the capabilities of an executable as follows:

getcap /path/to/program

In case of setcap -r, all capabilities will be gone and the result of getcap will be empty where as the '-ep' just removes what you added with '+ep'.

This comes in handy when you gave multiple capabilities and want to selectively remove them.

Matthias Braun
  • 7,797
  • 7
  • 45
  • 54
Arun GK
  • 321
  • 2
  • 3