Linux之文件属性与权限

修改文件属性与权限

  • chgrp – 修改文件所属用户组
  • chown – 修改文件拥有者
  • chmod – 修改文件的权限 SUID SGID SBIT

chgrp – chgrp [-R] [用户组] 文件或目录

  • -R – 进行递归修改。
chgrp -R group1 /usr/share # 改变share这个目录的所属组 -R就是指share下的所有子文件都改变所属组

grouadd : 用户组的添加
groupdel : 删除用户组
goupmod : 修改用户组信息
groups : 显示用户所属的用户组 – 如:group root

  • 用户(user)的工具和命令

useradd : 添加用户

主要参数有
-G 指定加入所属附加组
-g 指定默认组–>不建议修改
将一个用户从某个组中删除
gpasswd -d user group
passwd : 为用户设置密码
usermod : 修改用户信息
如修改登录名,用户家目录
-a 就是将用户添加到新用户组中而不必离开原有的其它用户组,不过 一般配合-G 添加附加组来使用
id:查看用户uid gid 及所属用户组
su : 用户切换工具

chown – chown [-R] 帐号名字 文件目录 #修改文件拥有者

  • -R 和chgrp 一样 递归
    使用实例:
drwxr-xr-x. 2 root root 6 4月  20 12:26 testfile
[root@centos test] chown mac:gro1 testfile/
[root@centos test] ll
drwxr-xr-x. 2 mac gro1 6 4月  20 12:26 testfile

chown mac:gro1 testfile --> 就是改变testfile 的拥有者为mac 所属组为gro1

chmod 改变用户权限

  • chmod u=rwx ,g=rw,o=x testfile
  • chmod 764 testfile
  • chmod u-x,o+r testfile
  • chmod 修改文件目录下的内容父目录必须要给 执行(x)权限

rwx=421

  • 对文件来讲权限的性能为:
    • r = 可读取此一文件的实际内容,如读取文本文件的文字内容等
    • w = 可以编辑,新增或修改该文件的内容(但不包含删除该文件)
    • x = 该文件具有可以被系统执行的权限
  • 对目录来说 权限的功能为:
    • r = 读取目录中的内容
    • w = 修改目录中的内容
    • x = 访问目录

PS:

  • 要开放目录给任何人浏览时,应该至少要给 r 和 x 的权限
  • 能否读取到某个文件内容,跟该文件的目录也有关系,目录至少要有 x 权限
  • 示列:在/tmp 下创建一个test 目录并给771
[root@centos tmp]# mkdir test	
[root@centos tmp]# ll
总用量 0
drwxr-xr-x. 2 root root 6 4月  20 15:23 test
[root@centos tmp]# chmod 771 test
# 这里给test目录一个771 —-->即只有一个执行权限 
[root@centos tmp]# vim ./test/a
[root@centos tmp]# ll ./test
总用量 4
-rw-r--r--. 1 root root 20 4月  20 15:24 a
[root@centos tmp]# chmod 772 ./test/a
[root@centos tmp]# su - mac
上一次登录:一 4月 20 15:00:13 CST 2020pts/0 上
[mac@centos ~]$ cd /tmp/
[mac@centos tmp]$ ls
test
[mac@centos tmp]$ cd test
[mac@centos test]$ ls
ls: 无法打开目录.: 权限不够
[mac@centos test]$ echo testmac >> a
[mac@centos test]$ cat a 
cat: a: 权限不够
[mac@centos test]$ vim b
[mac@centos test]$ su - root
密码:
上一次登录:一 4月 20 15:01:05 CST 2020pts/0 上
[root@centos ~]# cat /tmp/test/a
this is test file 

testmac
#这里可以看到目录有执行权限可以写入~

要对文件或目录 删除必须 得到上一级目录的 w 写入权限

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值