chmod命令

chmod 4755 中,4就是 s的意思;


chmod a+s test 相当于 chmod ug+s test(s 只对 user 和 group 有意义)
chmod u+s test 后,test 就是一个 set-user-id 的命令
chmod g+s test 后,test 就是一个 set-group-id 的命令
假设有一个 set-uid 的命令 foo,它的 owner 是 user1,则当另一个用户 user2 运行 foo 时,user2 就具有了 user1 的权限
考虑 passwd 命令:
用户的口令是存在 /etc/shadow 中的,普通用户不能读写 shadow 文件,为什么普通用户却能用 passwd 来修改自己的口令呢?原因就是 passwd 是个 set-uid 的命令,passwd 的 owner 是 root,普通用户运行 passwd 时就具有了 root 的权限,因此也就可以修改 shadow 了


chmod 750 a.out

改变 a.out的权限为750;
chmod a+x a.out
对所有用户增加 a.out的执行权限,a(All)表示所有用户;
chmod u=rwx a.out
设置属主的权限为读、写和执行, u(user)表示属主用户;
chmod g+rw a.out
增加同组用户的读写权限, g(group)表示同组用户;
chmod o-w a.out
减少其他用户的写权限, o(others)表示其他用户;
chmod go= a.out
清除同组和其他用户的所有权限;
chmod o=u-w a.out

范例 :将档案 file1.txt 设为所有人皆可读取 :
chmod ugo+r file1.txt
将档案 file1.txt 设为所有人皆可读取 :
chmod a+r file1.txt
将档案 file1.txt 与 file2.txt 设为该档案拥有者,与其所属同一个群体者可写入,但其他以外的人则不可写入 :
chmod ug+w,o-w file1.txt file2.txt
将 ex1.py 设定为只有该档案拥有者可以执行 :
chmod u+x ex1.py
将目前目录下的所有档案与子目录皆设为任何人可读取 :
chmod -R a+r *
此外chmod也可以用数字来表示权限如 chmod 777 file
语法为:chmod abc file
其中a,b,c各为一个数字,分别表示User、Group、及Other的权限。
r=4,w=2,x=1
若要rwx属性则4+2+1=7;
若要rw-属性则4+2=6;
若要r-x属性则4+1=7。
范例:
chmod a=rwx file

chmod 777 file
效果相同
chmod ug=rwx,o=x file

chmod 771 file
效果相同
若用chmod 4755 filename可使此程序具有root的权限
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值