码迷,mamicode.com
首页 > 系统相关 > 详细

Linux权限相关操作命令

时间:2017-12-19 00:50:54      阅读:289      评论:0      收藏:0      [点我收藏+]

标签:删除用户   facl   token   登录密码   .sh   mask   log   not   access   

以下是关于创建用户,设置用户密码,以及查看文件权限,给用户设置权限的一系列操作过程。

#查看当前用户的信息
[root@VM_64_7_centos tmp]# id
uid=0(root) gid=0(root) groups=0(root)
#查看是否存在test用户,以及用户信息
[root@VM_64_7_centos tmp]# id test
id: test: no such user
[root@VM_64_7_centos tmp]# id root
uid=0(root) gid=0(root) groups=0(root)

#创建新的用户
[root@VM_64_7_centos tmp]# useradd test
[root@VM_64_7_centos tmp]# id
uid=0(root) gid=0(root) groups=0(root)
[root@VM_64_7_centos tmp]# id test
uid=1000(test) gid=1000(test) groups=1000(test)

#将test用户添加到root组
[root@VM_64_7_centos tmp]# gpasswd -a test root
Adding user test to group root
[root@VM_64_7_centos tmp]# id test
uid=1000(test) gid=1000(test) groups=1000(test),0(root)
#将test移出root组
[root@VM_64_7_centos tmp]# gpasswd -d test root
Removing user test from group root
[root@VM_64_7_centos tmp]# id test
uid=1000(test) gid=1000(test) groups=1000(test)

#设置test用户的登录密码
[root@VM_64_7_centos ~]# passwd test
Changing password for user test.
New password:
Retype new password:
passwd: all authentication tokens updated successfully.
[test@VM_64_7_centos tmp]$ id
uid=1000(test) gid=1000(test) groups=1000(test)

#切换root用户
[test@VM_64_7_centos tmp]$ su - root
Password:
[root@VM_64_7_centos tmp]# id
uid=0(root) gid=0(root) groups=0(root)
[root@VM_64_7_centos tmp]#

#删除用户
[root@VM_64_7_centos tmp]# userdel -r test
[root@VM_64_7_centos tmp]# id test
id: test: no such user

#查看文件详细信息,包含文件操作的权限(r--r--r--)
# r:可读(4) w:可写(2) x:可执行(1)
# 文件权限分三组,第一组user,自身用户权限;第二组group,用户组权限;第三者other,其他用户权限
# u:代表自身用户;g:代表用户组;o:代表其他用户;a:代表所有用户
[root@VM_64_7_centos tmp]# ls -l
total 8
-r--r--r-- 1 root root 616 Dec 18 13:48 test.sh
[root@VM_64_7_centos tmp]# chmod g+w o+x ./test.sh
chmod: cannot access ‘o+x‘: No such file or directory
[root@VM_64_7_centos tmp]# chmod g+w ./test.sh
[root@VM_64_7_centos tmp]# ls -l
total 8
-r--rw-r-- 1 root root 616 Dec 18 13:48 test.sh
[root@VM_64_7_centos tmp]# chmod u+wx ./test.sh
[root@VM_64_7_centos tmp]# ls -l
total 8
-rwxrw-r-- 1 root root 616 Dec 18 13:48 test.sh
[root@VM_64_7_centos tmp]# chmod o+x ./test.sh
[root@VM_64_7_centos tmp]# ls -l
total 8
-rwxrw-r-x 1 root root 616 Dec 18 13:48 test.sh
[root@VM_64_7_centos tmp]# chmod a-rwx ./test.sh
[root@VM_64_7_centos tmp]# ls -l
total 8
---------- 1 root root 616 Dec 18 13:48 test.sh
[root@VM_64_7_centos tmp]# chmod u+rwx ./test.sh
[root@VM_64_7_centos tmp]# ls -l
total 8
-rwx------ 1 root root 616 Dec 18 13:48 test.sh


[root@VM_64_7_centos tmp]# ls -l
total 8
-rwx------ 1 root root 616 Dec 18 13:48 test.sh
[root@VM_64_7_centos tmp]# chmod 000 ./test.sh
[root@VM_64_7_centos tmp]# ls -l
total 8
---------- 1 root root 616 Dec 18 13:48 test.sh
[root@VM_64_7_centos tmp]# chmod u+001 ./test.sh
chmod: invalid mode: ‘u+001‘
Try ‘chmod --help‘ for more information.
[root@VM_64_7_centos tmp]# chmod 001 ./test.sh
[root@VM_64_7_centos tmp]# ls -l
total 8
---------x 1 root root 616 Dec 18 13:48 test.sh
[root@VM_64_7_centos tmp]# chmod 020 ./test.sh
[root@VM_64_7_centos tmp]# ls -l
total 8
-----w---- 1 root root 616 Dec 18 13:48 test.sh
[root@VM_64_7_centos tmp]# chmod 400 ./test.sh
[root@VM_64_7_centos tmp]# ls -l
total 8
-r-------- 1 root root 616 Dec 18 13:48 test.sh
[root@VM_64_7_centos tmp]# chmod 600 ./test.sh
[root@VM_64_7_centos tmp]# ls -l
total 8
-rw------- 1 root root 616 Dec 18 13:48 test.sh
[root@VM_64_7_centos tmp]# chmod 700 ./test.sh
[root@VM_64_7_centos tmp]# ls -l
total 8
-rwx------ 1 root root 616 Dec 18 13:48 test.sh
[root@VM_64_7_centos tmp]# chmod 744 test.sh
[root@VM_64_7_centos tmp]# ls -l
total 8
-rwxr--r-- 1 root root 616 Dec 18 13:48 test.sh
[root@VM_64_7_centos tmp]#


#查看文件权限
[root@VM_64_7_centos tmp]# getfacl test.sh
# file: test.sh
# owner: root
# group: root
user::rwx
group::r-x
other::r-x

#设置文件权限
[root@VM_64_7_centos tmp]# setfacl -m u:test:rwx test.sh
[root@VM_64_7_centos tmp]# getfacl test.sh
# file: test.sh
# owner: root
# group: root
user::rwx
user:test:rwx
group::r-x
mask::rwx
other::r-x

#删除文件权限
[root@VM_64_7_centos tmp]# setfacl -x user:test test.sh
[root@VM_64_7_centos tmp]# getfacl test.sh
# file: test.sh
# owner: root
# group: root
user::rwx
group::r-x
mask::r-x
other::r-x

[root@VM_64_7_centos tmp]# ls -l
total 8
-rwxr-xr-x+ 1 root root 616 Dec 18 13:48 test.sh

#清空文件权限到设置权限之前的权限状态
[root@VM_64_7_centos tmp]# setfacl -b test.sh
[root@VM_64_7_centos tmp]# getfacl test.sh
# file: test.sh
# owner: root
# group: root
user::rwx
group::r-x
other::r-x

[root@VM_64_7_centos tmp]#


Linux权限相关操作命令

标签:删除用户   facl   token   登录密码   .sh   mask   log   not   access   

原文地址:http://www.cnblogs.com/advancing/p/8058831.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!