当前位置:首页> 正文

chmod命令|虚拟机chmod命令

chmod命令|虚拟机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的权限

展开全文阅读

相关内容