linux 权限管理(命令)

linux 权限管理(命令)

chmod

chmod {ugoa}{+-=}{rwx} [文件或目录]
或
chmod 777 [文件或目录]
	-R 递归修改权限
  • 其中u表示所有者,g表示所属组,g表示其他,+表示添加权限,-表示去除权限,=表示赋予权限
  • r表示读取权限,w表示写的权限,x表示执行的权限
  • 常用的权限命令用数字表示其中r,w,x代表的值如下所示

key Value
r 4
w 2
x 1

eg

项目 Value
-rwx–x-w- 可用 712表示
-rwxrwxrwx 可用777表示
-r–r--r– 可用444表示
  • 操作实例
//原生rwx操作
[root@localhost ~]# ls -l
d--x--x--x. 3 root root 4096 Jan 23 12:35 h1
[root@localhost ~]# chmod u=rwx,g-x,o+r h1
[root@localhost ~]# ls -l
drwx---r-x. 3 root root 4096 Jan 23 12:35 h1
[root@localhost ~]# 
//使用数字代表rwx
[root@localhost ~]# ls -l
-rwx--x-w-. 1 root root    0 Jan 23 12:36 k1
[root@localhost ~]# chmod 733 k1
[root@localhost ~]# ls -l
-rwx-wx-wx. 1 root root    0 Jan 23 12:36 k1
//递归修改权限
[root@localhost ~]# ls -l
drwx---r-x. 3 root root 4096 Jan 23 12:35 h1
[root@localhost ~]# ls -l h1/
d--x--x--x. 2 root root 4096 Jan 23 12:35 h5
[root@localhost ~]# chmod 444 -R h1
[root@localhost ~]# ls -l
dr--r--r--. 3 root root 4096 Jan 23 12:35 h1
[root@localhost ~]# ls -l h1/
dr--r--r--. 2 root root 4096 Jan 23 12:35 h5

rwx权限的再理解

key 文件 目录
r 可以读取文件类容(more,less,cat,head,tail) 可以查看目录内内容(ls)
w 可以修改文件内容(vim) 可以在目录内创建,删除文件(touch,mkdir/rmdir/rm)
x 可以执行文件 (script,command) 可以进入目录(cd)

chown

chown [目标用户][文件或目录]   //修改文件所有着(只有root有权限修改用户所有者)
	-R 递归修改
eg :[root@localhost ~]# useradd qq
	[root@localhost ~]# passwd qq
	Changing password for user qq.
	New password: 
	BAD PASSWORD: The password is shorter than 7 characters
	Retype new password: 
	passwd: all authentication tokens updated successfully.
	[root@localhost ~]# ls -l
	dr--r--r--. 3 root root 4096 Jan 23 12:35 h1
	[root@localhost ~]# chown qq h1
	[root@localhost ~]# ls -l
	dr--r--r--. 3 qq   root 4096 Jan 23 12:35 h1

chgrp

chgrp [目标组][操作文件] //修改用户所属组
	-R 递归修改
eg: [root@localhost ~]# ls -l
	dr--r--r--. 3 qq   baidu 4096 Jan 23 12:35 h1
	[root@localhost ~]# chgrp root h1
	[root@localhost ~]# ls -l
	dr--r--r--. 3 qq   root 4096 Jan 23 12:35 h1

umask

umask -S //显示新建文件的缺省权限
umask [777] 设置新建文件的缺省权限
//在Linux新建的文件默认是没有x权限的
//当我们直接输入umask命令时看到的是0022
[root@localhost ~]# umask
0022
//其中第一个零表示特殊权限,后面的022表示缺省权限
//022对应 ----w--w-
//	补码  rwxr-xr-x  即表示755,即默认创建的文件的权限为755
//当然也可以自定义默认创建文件权限用 umask [缺省码]即可
发布了27 篇原创文章 · 获赞 7 · 访问量 1092

猜你喜欢

转载自blog.csdn.net/qq_36917605/article/details/104075387