首页 技术 正文
技术 2022年11月9日
0 收藏 610 点赞 4,257 浏览 3846 个字

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

#查看当前用户的信息
[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]#

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,490
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,905
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,738
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,491
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:8,129
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:5,292