给文件赋予能力,下面以date为例
[bp@bogon ~]$ whereis -b date //如果去掉-b会显示额外的其他路径
date: /usr/bin/date
[bp@bogon ~]$ cp /usr/bin/date . //复制date命令到当前文件夹
[bp@bogon ~]$ ls
date Desktop Documents Downloads Music Pictures Public Templates Videos
[bp@bogon ~]$ ./date //查看时间正常
Thu Jun 7 13:24:32 PDT 2018
[bp@bogon ~]$ ./date -s "2018-06-07 13:29" //无法设置时间
./date: cannot set date: Operation not permitted
Thu Jun 7 13:29:00 PDT 2018
[bp@bogon ~]$ setcap "cap_sys_time=pe" ./date //给它赋予能力,但需要sudo才可以正常赋予能力,p指许可值,e值有效值
unable to set CAP_SETFCAP effective capability: Operation not permitted
[bp@bogon ~]$ sudo setcap "cap_sys_time=pe" ./date
[bp@bogon ~]$ ./date -s "2018-06-07 13:31"
Thu Jun 7 13:31:00 PDT 2018
[bp@bogon ~]$
[bp@bogon ~]$ getcap ./date
./date = cap_sys_time+ep