Linux Permissions Related Operations command

Source: Internet
Author: User
Tags file permissions

Here are a series of procedures for creating users, setting user passwords, and viewing file permissions to set permissions for users.

#查看当前用户的信息
[[Email Protected]_64_7_centos tmp]# ID
Uid=0 (Root) gid=0 (root) groups=0 (root)
#查看是否存在test用户, and user information
[[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

#查看文件详细信息, including permissions for file operations (r--r--r--)
# r: Readable (4) W: Writable (2) x: Executable (1)
# file permissions are divided into three groups, the first group of users, their own user rights; second group, user group permissions; third other, additional user rights
# U: On behalf of the user, G: On behalf of the user group, O: On behalf of other users; A: representing All users
[Email Protected]_64_7_centos tmp]# ls-l
Total 8
-r--r--r--1 root root 616 Dec 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 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 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 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 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 13:48 test.sh


[Email Protected]_64_7_centos tmp]# ls-l
Total 8
-rwx------1 root root 616 Dec 13:48 test.sh
[[Email Protected]_64_7_centos tmp]#chmod/test.sh.
[Email Protected]_64_7_centos tmp]# ls-l
Total 8
----------1 root root 616 Dec 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
---------x1 root root 616 Dec 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 13:48 test.sh
[[Email Protected]_64_7_centos tmp]#chmod./test.sh
[Email Protected]_64_7_centos tmp]# ls-l
Total 8
-r--------1 root root 616 Dec 13:48 test.sh
[[Email Protected]_64_7_centos tmp]#chmod./test.sh
[Email Protected]_64_7_centos tmp]# ls-l
Total 8
-rw-------1 root root 616 Dec 13:48 test.sh
[[Email Protected]_64_7_centos tmp]#chmod./test.sh
[Email Protected]_64_7_centos tmp]# ls-l
Total 8
-rwx------1 root root 616 Dec 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 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 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]#


Linux Permissions Related Operations command

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.