linux权限相关的命令,Linux权限相关操作命令(示例代码)

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

#查看当前用户的信息

[[email protected]_64_7_centos tmp]# id

uid=0(root) gid=0(root) groups=0(root)

#查看是否存在test用户,以及用户信息

[[email protected]_64_7_centos tmp]# id test

id: test: no such user

[[email protected]_64_7_centos tmp]# id root

uid=0(root) gid=0(root) groups=0(root)

#创建新的用户

[[email protected]_64_7_centos tmp]# useradd test

[[email protected]_64_7_centos tmp]# id

uid=0(root) gid=0(root) groups=0(root)

[[email protected]_64_7_centos tmp]# id test

uid=1000(test) gid=1000(test) groups=1000(test)

#将test用户添加到root组

[[email protected]_64_7_centos tmp]# gpasswd -a test root

Adding user test to group root

[[email protected]_64_7_centos tmp]# id test

uid=1000(test) gid=1000(test) groups=1000(test),0(root)

#将test移出root组

[[email protected]_64_7_centos tmp]# gpasswd -d test root

Removing user test from group root

[[email protected]_64_7_centos tmp]# id test

uid=1000(test) gid=1000(test) groups=1000(test)

#设置test用户的登录密码

[[email protected]_64_7_centos ~]# passwd test

Changing password for user test.

New password:

Retype new password:

passwd: all authentication tokens updated successfully.

[[email protected]_64_7_centos tmp]$ id

uid=1000(test) gid=1000(test) groups=1000(test)

#切换root用户

[[email protected]_64_7_centos tmp]$ su - root

Password:

[[email protected]_64_7_centos tmp]# id

uid=0(root) gid=0(root) groups=0(root)

[[email protected]_64_7_centos tmp]#

#删除用户

[[email protected]_64_7_centos tmp]# userdel -r test

[[email protected]_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:代表所有用户

[[email protected]_64_7_centos tmp]# ls -l

total 8

-r--r--r-- 1 root root 616 Dec 18 13:48 test.sh

[[email protected]_64_7_centos tmp]# chmod g+w o+x ./test.sh

chmod: cannot access ‘o+x‘: No such file or directory

[[email protected]_64_7_centos tmp]# chmod g+w ./test.sh

[[email protected]_64_7_centos tmp]# ls -l

total 8

-r--rw-r-- 1 root root 616 Dec 18 13:48 test.sh

[[email protected]_64_7_centos tmp]# chmod u+wx ./test.sh

[[email protected]_64_7_centos tmp]# ls -l

total 8

-rwxrw-r-- 1 root root 616 Dec 18 13:48 test.sh

[[email protected]_64_7_centos tmp]# chmod o+x ./test.sh

[[email protected]_64_7_centos tmp]# ls -l

total 8

-rwxrw-r-x 1 root root 616 Dec 18 13:48 test.sh

[[email protected]_64_7_centos tmp]# chmod a-rwx ./test.sh

[[email protected]_64_7_centos tmp]# ls -l

total 8

---------- 1 root root 616 Dec 18 13:48 test.sh

[[email protected]_64_7_centos tmp]# chmod u+rwx ./test.sh

[[email protected]_64_7_centos tmp]# ls -l

total 8

-rwx------ 1 root root 616 Dec 18 13:48 test.sh

[[email protected]_64_7_centos tmp]# ls -l

total 8

-rwx------ 1 root root 616 Dec 18 13:48 test.sh

[[email protected]_64_7_centos tmp]# chmod 000 ./test.sh

[[email protected]_64_7_centos tmp]# ls -l

total 8

---------- 1 root root 616 Dec 18 13:48 test.sh

[[email protected]_64_7_centos tmp]# chmod u+001 ./test.sh

chmod: invalid mode: ‘u+001‘

Try ‘chmod --help‘ for more information.

[[email protected]_64_7_centos tmp]# chmod 001 ./test.sh

[[email protected]_64_7_centos tmp]# ls -l

total 8

---------x 1 root root 616 Dec 18 13:48 test.sh

[[email protected]_64_7_centos tmp]# chmod 020 ./test.sh

[[email protected]_64_7_centos tmp]# ls -l

total 8

-----w---- 1 root root 616 Dec 18 13:48 test.sh

[[email protected]_64_7_centos tmp]# chmod 400 ./test.sh

[[email protected]_64_7_centos tmp]# ls -l

total 8

-r-------- 1 root root 616 Dec 18 13:48 test.sh

[[email protected]_64_7_centos tmp]# chmod 600 ./test.sh

[[email protected]_64_7_centos tmp]# ls -l

total 8

-rw------- 1 root root 616 Dec 18 13:48 test.sh

[[email protected]_64_7_centos tmp]# chmod 700 ./test.sh

[[email protected]_64_7_centos tmp]# ls -l

total 8

-rwx------ 1 root root 616 Dec 18 13:48 test.sh

[[email protected]_64_7_centos tmp]# chmod 744 test.sh

[[email protected]_64_7_centos tmp]# ls -l

total 8

-rwxr--r-- 1 root root 616 Dec 18 13:48 test.sh

[[email protected]_64_7_centos tmp]#

#查看文件权限

[[email protected]_64_7_centos tmp]# getfacl test.sh

# file: test.sh

# owner: root

# group: root

user::rwx

group::r-x

other::r-x

#设置文件权限

[[email protected]_64_7_centos tmp]# setfacl -m u:test:rwx test.sh

[[email protected]_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

#删除文件权限

[[email protected]_64_7_centos tmp]# setfacl -x user:test test.sh

[[email protected]_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

[[email protected]_64_7_centos tmp]# ls -l

total 8

-rwxr-xr-x+ 1 root root 616 Dec 18 13:48 test.sh

#清空文件权限到设置权限之前的权限状态

[[email protected]_64_7_centos tmp]# setfacl -b test.sh

[[email protected]_64_7_centos tmp]# getfacl test.sh

# file: test.sh

# owner: root

# group: root

user::rwx

group::r-x

other::r-x

[[email protected]_64_7_centos tmp]#

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值