Linux入门详解 (8)

   命令演示:

[root@localhost /]# id NewUser uid=1001(NewUser) gid=1001(NewUser) groups=1001(NewUser) [root@localhost /]# usermod -u1020 -gyunya -cnew_user_message NewUser [root@localhost /]# id NewUser uid=1020(NewUser) gid=1000(yunya) groups=1000(yunya) [root@localhost /]#

   passwd命令

命令/选项 描述
passwd [选项] [用户名]   如果选项为空,则修改用户密码  
选项:-l   锁定口令,即禁用该用户  
选项:-u   解锁口令,即接出该用户的禁用状态  
选项:-d   使该账号无口令  
选项:-f   强迫用户下次登陆时修改口令  
群组相关命令

   grounpmod命令

命令/选项 描述
grounpmod [选项] [群组名]   修改现有的组名相关信息及权限  
选项:-g   修改群组的GID  
选项:-n   修改群组的名称  
选项:-G   将用户加入到一个指定的组中  
选项:-L   锁定群组,该群组下的用户将不能登录  
选项:-U   解锁群组,该群组下的用户将可以登录  

   groupdel命令

命令 描述
grounpmod [群组名]   删除一个已有的群组  
权限相关篇 文件权限操作

   使用命令ll可查看一个文件的详细信息,如下所示:

[root@localhost ~]# touch test [root@localhost ~]# ll test -rw-r--r--. 1 root root 0 Jan 30 05:19 test

   -rw-r--r--属于文件权限信息,1是连接数,第一个root是创建者(属主),第二个root是创建者所属的群组(属组),后面的信息是文件展位字节大小与时间。

   对于权限信息来说,它分为10个部分:

   第一部分:第1位置,-是普通文件,d是目录文件,b是块文件,p是管道文件,l是软链接

   第二部分:第2、3、4位,代表属主的权限,-是无权限,r是读权限,w是写权限,x是可执行权限

   第三部分:第5、6、7位,代表属组的权限,-是无权限,r是读权限,w是写权限,x是可执行权限

   第四部分:第8、9、10位,代表其他用户的权限(即除了root和属主之外的用户权限),-是无权限,r是读权限,w是写权限,x是可执行权限

   另外,root权限用户高于其他所有,不可对其进行限制

   执行可执行文件

   如果具有x权限,代表该文件可执行,执行方式如下:

# 方式1 sh [文件名] # 方式2 ./ [文件名]

   权限修改命令chmod

   修改文件权限的命令是chmod,分别有在原有基础上的 +-权限方法,如原本只有 r--则可以修改成 +xw 就成了 rxw 了。还有一种就是 = 赋值法,清除原有权限,赋予新的权限。

   chmod uga=(取消全部权限)-(只用输入一个) 用a可以直接等同于 uga= 的操作

   u是属主,g是属组,o是其他用户,a是全部

# 取消所有权限 [root@localhost ~]# chmod uga= test [root@localhost ~]# ll test ----------. 1 root root 0 Jan 30 05:19 test # 取消所有权限 [root@localhost ~]# chmod a= test [root@localhost ~]# ll test ----------. 1 root root 0 Jan 30 05:19 test # 增加所有权限 [root@localhost ~]# chmod a=rwx test [root@localhost ~]# ll test -rwxrwxrwx. 1 root root 0 Jan 30 05:19 test # 取消属组的所有权限 [root@localhost ~]# chmod g= test [root@localhost ~]# ll test -rwx---rwx. 1 root root 0 Jan 30 05:19 test # 取消用户的所有权限 [root@localhost ~]# chmod u= test [root@localhost ~]# ll test -------rwx. 1 root root 0 Jan 30 05:19 test # 给属组增加所有权限 [root@localhost ~]# chmod g=rwx test [root@localhost ~]# ll test ----rwxrwx. 1 root root 0 Jan 30 05:19 test # 修改属组的权限只有r [root@localhost ~]# chmod g=r test [root@localhost ~]# ll test ----r--rwx. 1 root root 0 Jan 30 05:19 test # 修改属组的权限在原有基础上增加w [root@localhost ~]# chmod g+w test [root@localhost ~]# ll test ----rw-rwx. 1 root root 0 Jan 30 05:19 test # 修改属组的权限在原有基础上减少w [root@localhost ~]# chmod g-r test [root@localhost ~]# ll test ----r--rwx. 1 root root 0 Jan 30 05:19 test # 修改其他用户的权限在原有基础上减少x [root@localhost ~]# chmod o-x test [root@localhost ~]# ll test ----r--r-x. 1 root root 0 Jan 30 05:19 test [root@localhost ~]# 目录权限操作

   使用ll -d来查看某个目录的详细信息,如下所示:

[root@localhost ~]# mkdir testDir [root@localhost ~]# ll -d testDir drwxr-xr-x. 2 root root 6 Jan 30 05:51 testDir

   对于目录的可读权限来说,意味着能够查看该目录下的内容。

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wpjxxz.html