0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

setcap cli

0
Posted at

setcap 是 Linux 中用于管理 Capabilities(权能)的工具。

它的核心作用是:让普通用户运行的程序也能拥有特定的“特权”,而不需要赋予完整的 root 权限。

在 Linux 中,传统的权限模型只有两种:普通用户(受限)和 root(全能)。setcap 将 root 的权限拆分成了许多小块(即 Capabilities),你可以根据需要只把其中的一两块分给某个程序。

sudo setcap cap_net_raw,cap_net_admin=eip ./file

cap_net_raw:允许程序创建 原始套接字 (Raw Sockets)。这通常用于抓包、伪造数据包或执行类似 ping 的操作。

cap_net_admin:允许程序执行网络管理任务。例如修改路由表、配置网卡、设置防火墙规则等。

=eip:这是权限的生效方式:

e (Effective):权限立即生效。

i (Inheritable):权限可以被子进程继承。

p (Permitted):进程被允许拥有这些权限。

注意:如果重新编译了程序,或者是通过 cp 覆盖了该文件,之前设置的 Capabilities 通常会丢失,需要重新执行 setcap。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?