[命令集3.1]linux文件的权限
用 chmod 和 chown 更改访问权限和所有权。对于所有用户的默认掩码(umask)可以在 /etc/profile (Linux)
或 /etc/login.conf (FreeBSD) 中修改。其默认掩码(umask)通常为 022。掩码可以和777做减法,从而得到755
的权限。
1 –x 执行 # Mode 764 = 执行/读/写 | 读/写 | 读
2 -w- 写 # |—所有者|—用户组|—其他用户|
4 r– 读
ugo=a u=所有者, g=用户组, o=其他用户, a=所有用户
# chmod [OPTION] MODE[,MODE] FILE # MODE 可以是 [ugoa]*([-+=]([rwxXst])) # chmod 640 /var/log/maillog # 更改 maillog 访问权限为 -rw-r----- # chmod u=rw,g=r,o= /var/log/maillog # 同上 # chmod -R o-r /home/* # 递归去除所有其他用户的可读权限 在可执行位设置 SUID (知道你在干什么!13) # chmod u+s /path/to/prog # # find / -perm -u+s -print # 查找所有设置过 SUID 位的程序 # chown user:group /path/to/file # 改变文件的所有者和文件关联的组 # chgrp group /path/to/file # 改变文件关联的组 # chmod 640 `find ./ -type f -print` # Change permissions to 640 for all files # chmod 751 `find ./ -type d -print` # Change permissions to 751 for all directories |
