5.1-基本权限管理

# demo root用户创建一个文件,移动到/目录。切换其他用户,有几种方式让其他用户能读写?

# 权限
touch test.txt
# 输出内容的含义
# -/l/d
# 我买的冰箱 家里人可用  邻居家坏了临时可用
# 组 u g o a 所属者(r) 所属组(g) 其他组(o) 3个都设置(a)  
# 值 r w x 读(r) 写(w) 执行(x)
# 操作符 + - =
# 组 操作符 值 例如 a=rwx
ls -l test.txt

id liujunbao
# 现象:/root/test.txt 即使 test.txt 设置 o=r  liujunbao 也没有权限操作 不能再别人家随心所欲
mv test.txt /
ls -l /test.txt
su - liujunbao
echo ss > /test.txt
eixt


# 1.修改其他组权限
chmod o+w /test.txt 
ls -l /test.txt
su - liujunbao
echo ss > /test.txt
cat /test.txt
# a all 给 u g o 一起设置
chmod a+w /test.txt
chmod o-w /test.txt
ls -l /test.txt


# 2.改变文件所属者
# 语法 chown user:group 文件
chown liujunbao:root /test.txt


# 3.添加到用户组
gpasswd -a liujunbao root



# 推荐数字方式 r=4 w=2 x=1 
# 相当于下面注释的 3 条命令
chmod 644 /test.txt
ls -l /test.txt
# chmod u=rw /test.txt
# chmod g=r /test.txt
#chmod o=r /test.txt

上一节:4.4-组账户管理

下一节:5.2-隐藏权限