Linux基本功杂记——[020]——『Linux Capability』

『Linux Capability』

  For the purpose of performing permission checks, traditional UNIX implementations distinguish two categories of processes: privileged processes (whose effective user ID is 0, referred to as superuser or root), and unprivileged processes (whose effective UID is nonzero).

  Privileged processes bypass all kernel permission checks, while unprivileged processes are subject to full permission checking based on the process‘s credentials (usually: effective UID, effective GID, and supplementary group list).

  Starting with kernel 2.2, Linux divides the privileges traditionally associated with superuser into distinct units, known as capabili‐ties, which can be independently enabled and disabled. Capabilities are a per-thread attribute.

一、kernel配置

二、源码中权限相关注释(/usr/src/linux-*.*.*/include/linux/cred.h):

其中定义了进程的三个能力位:inheritable(I)、permitted(P)和effective(E)

  • cap_permitted:当一个进程将执行某项特权操作时,操作系统会检查cap_effective中对应位是否有效,而不再检查进程euid是否为0
  • cap_permitted:表示进程实际能够使用的能力,在cap_permitted中可以包含cap_effective中没有的能力
  • cap_inheritable表示能够被目标程序启动的子进程继承的能力

三、setcap、getcap:用户层的用途是,将系统中具有suid、sgid权限位的文件,以更安全的capability机制管理,减少潜在的程序漏洞带来的危害

root # find / -perm /4000
root # find / -perm /2000

『应用示例 一』

  ping只需要CAP_NET_RAW能力,即可在具有x权限的环境中执行,并不需要suid权限

  /* CAP_NET_RAW:use RAW and PACKET sockets;bind to any address for transparent proxying */

root # chown u-s /bin/ping
root # setcap CAP_NET_RAW+ep /bin/ping
root # getcap /bin/ping
/bin/ping = cap_net_raw+ep

『应用示例 二』

  使普通用户可执行iftop

root # setcap CAP_NET_RAW+ep /usr/sbin/iftop

『应用示例 三』

  使普通用户可以使用chvt切换虚拟工作台

root # setcap cap_dac_read_search,cap_sys_tty_config+ep /usr/bin/chvt

  

时间: 2024-08-24 05:00:34

Linux基本功杂记——[020]——『Linux Capability』的相关文章

Linux基本功杂记——[020]——『ext4 Quota』

一.关闭selinux [[email protected]6 home]# sestatus -v SELinux status: disabled 示例:临时关闭 [[email protected]6 home]# setenforce 0 示例:永久关闭 [[email protected]6 home]# vi /etc/selinux/config SELINUX=disabled 二.在/etc/fstab中添加usrquota.grpquota挂载参数 /dev/mapper/V

Linux基本功杂记——[018]——『Network Bonding』

EtherChannel最初是由cisco提出,通过聚合多条物理链路为单条逻辑链路,从而实现高可用及提高吞吐量等目的.AgP(Port Aggregation Protocol,Cisco专有协议).LACP(IEEE 802.3ad)是应用最广泛的两种实现.Linux中的实现称为Bonding,HA的实现需要系统层面Bonding和物理层面switch紧密配合. http://www.mjmwired.net/kernel/Documentation/networking/bonding.tx

Linux基本功杂记——[013]——『mdadm Raid & LVM』

>FOR FREEDOM!< {A} Introduction Here's a short description of what is supported in the Linux RAID drivers. RAID is not a guarantee for data integrity, it just allows you to keep your data if a disk dies. The current RAID drivers in Linux support the

Linux基本功杂记——[021]——『rhel6系列的开、关机脚本』

一.系统脚本位置及含义 /etc/inittab./etc/init/* 存放开关机配置文件 /etc/init.d/* 服务脚本,是一个到/etc/rc.d/init.d/的软链接 /etc/rc.d 存放各个运行level的开关机脚本,均为指向/etc/init.d目录的软链接 /etc/rc.loacl 系统启动最后阶段执行的脚本,可将需要开机运行的命令直接写在此文件中 二.启动脚本的基本语法 如下所示,chkconfig行的“2345”指默认在2.3.4.5四个level开机运行,“12

Linux基本功杂记——[007]——8月10日课后作业

/*答案不止一个,仅列出自认为最优雅的存在*/ 作业要求:编写BASH脚本实现题目要求的内容. 一.显示当前主机系统信息,包括主机名,IPv4地址,操作系统版本,内核版本,CPU型号,内存大小,硬盘大小 1 #!/usr/bin/bash 2 printf 3 " Hostname: $(hostname)\n \ 4 IPv4: $(ip addr | grep -oP '(\d+\.){3}\d+/\d+' | awk 'BEGIN{ORS=" "}{print}')\n

Linux基本功杂记——[017]——LFS构建逻辑理解

严格来说,LFS只能称为“pseudo LFS”,WHY? 因为LFS归根结底,还是基于已有的操作系统平台构建而来,并非真正的从0开始,它没有突破所谓“鸡与蛋”的死循环:但它确实有助于理解Linux的运行机理,通过刻意营造一个尽可能接近于原始状态的最小运行环境,给用户一种“接近从0开始”的系统DIY体验. 一.必须理解的概念 C的编译与链接,是一个将源代码转换成可在硬件上运行的程序的过程,从源代码到程序执行,通常需要5步:预编译.编译.汇编.链接.动态加载(动态链接).编译是把人类编写的程序代码

Linux基本功杂记——[023]——「OpenSSH tunneling」

SSH tunneling 相关 参考資料:http://www.ibm.com/developerworks/cn/linux/l-cn-sshforward/ 本地端口转发: 适用场景:发起端可以连接 SSH_server_host 端的 ssh 服务,但无法与最终目标 goal_host 的程序直接通信,而 SSH_server_host 可以 命令格式:ssh [-g] -L <local_port>:<goal_host>:<goal_port> [email

Linux基本功杂记——[010]——{rpm、yum及源码方式管理软件包}

一.yum配置文件位置 /etc/yum.conf /etc/yum.repos.d/*.repo 二.yum常用命令 install pkgs reinstall pkgs update pkgs update-to check-update erase pkgs list installed/updates info pkgs provides pkgs deplist pkgs repolist all/enabled/disabled history [info num] clean a

Linux基本功杂记——[002]——7月29日课后作业

1.file1文件的内容为:”1 2 3 4 5 6 7 8 9 10” 计算出所有数字的总和 方法一:[[email protected]7 fh]# echo $(tr ' ' '+' <file1) | bc 55 方法二:[[email protected]7 fh]# x=$(($(tr ' ' '+' <file1))) && echo $x 55 方法三:[[email protected]7 fh]# x=$(tr ' ' '+' <file1) | py