[1060a Series] Permission Management
I. Explanation of ls -l** Output**
ls -l
[root@1060a ~]# ls -l
total 8
-rw------- 1 root root 1206 Nov 2 19:40 anaconda-ks.cfg
drwxr-xr-x 2 root root 59 Nov 2 19:42 Desktop
drwxr-xr-x 2 root root 6 Nov 2 19:37 Documents
drwxr-xr-x 2 root root 6 Nov 2 19:37 Downloads
-rw------- 1 root root 1483 Nov 2 19:41 initial-setup-ks.cfg
drwxr-xr-x 2 root root 32 Nov 2 19:37 Music
drwxr-xr-x 3 root root 24 Nov 2 19:37 Pictures
drwxr-xr-x 2 root root 6 Nov 2 19:37 Videos
Each line can be divided into 8 fields:
-|rw------- | 1 | root | root | 1206 | Nov 2 19:40 | anaconda-ks.cfg
File Type: - indicates a regular file. Other types include:
-
d
l
b
Permissions: Divided into three groups (owner, group, others), with an additional + indicating ACL permissions.
+
Number of Links: For directories, this represents the number of subdirectories; for files, the number of hard links.
File Owner: The owner of the file.
Group Owner: The group owning the file.
File Size: Size of the file in bytes.
Last Modification Time: Last time the file content was modified. Use stat command to view all timestamps:
stat
[root@1060a ~]# stat anaconda-ks.cfg
II. Basic Permissions
Permissions define what actions users can perform on files. Basic permissions in Linux are:
r
w
x
Effect of Permissions on Files and Directories:
Files:
Directories:
Determining Permissions:
user > group > others
Modifying Permissions:
chmod
chmod [options] u/g/o/a +/-/= filename
u
g
o
a
chmod [options] permissions filename
755
chmod 777 file1
chmod 651 file1
chown
chown [options] [OWNER][:[GROUP]] FILE...
chown admin file1
chown :admin file1
chown user1:user1 file1
III. Special Permissions
Representation of Special Permissions
Types of Special Permissions:
chmod u+s filename
chmod g+s filename/dirname
chmod o+t dirname
Setting Special Permissions with Numeric Mode:
chmod 4xxx filename # SUIDchmod 2xxx filename/dirname # SGIDchmod 1xxx dirname# Sticky bit
IV. Hidden Permissions
Types of Hidden Permissions:
Managing Hidden Permissions:
chattr
chattr +/- permission filename
lsattr
lsattr filename
V. ACL Permissions
Access Control Lists (ACLs) provide fine-grained permissions for files and directories.
Viewing ACLs:
getfacl
getfacl filename
Setting ACLs:
setfacl
setfacl [options] filename/dirname
-m
-x
-b
-d
-k
-R
setfacl -m u:st:r file
setfacl -m g:stg:rx file
setfacl -x g:stg file
setfacl -x u:st file
setfacl -b file
setfacl -dm u:user1:rwx,g:user1:rx dir
No replies yet
Popular Ranking
Popular Events
[1060a Series] Permission Management
I. Explanation of
ls -l
** Output**[root@1060a ~]# ls -l
total 8
-rw------- 1 root root 1206 Nov 2 19:40 anaconda-ks.cfg
drwxr-xr-x 2 root root 59 Nov 2 19:42 Desktop
drwxr-xr-x 2 root root 6 Nov 2 19:37 Documents
drwxr-xr-x 2 root root 6 Nov 2 19:37 Downloads
-rw------- 1 root root 1483 Nov 2 19:41 initial-setup-ks.cfg
drwxr-xr-x 2 root root 32 Nov 2 19:37 Music
drwxr-xr-x 3 root root 24 Nov 2 19:37 Pictures
drwxr-xr-x 2 root root 6 Nov 2 19:37 Videos
Each line can be divided into 8 fields:
-|rw------- | 1 | root | root | 1206 | Nov 2 19:40 | anaconda-ks.cfg
File Type:
-
indicates a regular file. Other types include:d
: directoryl
: link fileb
: block device filePermissions: Divided into three groups (owner, group, others), with an additional
+
indicating ACL permissions.Number of Links: For directories, this represents the number of subdirectories; for files, the number of hard links.
File Owner: The owner of the file.
Group Owner: The group owning the file.
File Size: Size of the file in bytes.
Last Modification Time: Last time the file content was modified. Use
stat
command to view all timestamps:[root@1060a ~]# stat anaconda-ks.cfg
II. Basic Permissions
Permissions define what actions users can perform on files. Basic permissions in Linux are:
r
(read)w
(write)x
(execute)Effect of Permissions on Files and Directories:
Files:
r
: Read file content.w
: Modify file content.x
: Execute the file as a command.Directories:
r
: Read the directory content.w
: Modify directory content.x
: Enter the directory.Determining Permissions:
user > group > others
.Modifying Permissions:
chmod
to change permissions.chmod [options] u/g/o/a +/-/= filename
u
: userg
: groupo
: othersa
: allchmod [options] permissions filename
755
.chmod 777 file1
chmod 651 file1
chown
to change file owner and group:chown [options] [OWNER][:[GROUP]] FILE...
chown admin file1
chown :admin file1
chown user1:user1 file1
III. Special Permissions
Representation of Special Permissions
Types of Special Permissions:
chmod u+s filename
chmod g+s filename/dirname
chmod o+t dirname
Setting Special Permissions with Numeric Mode:
chmod 4xxx filename # SUIDchmod 2xxx filename/dirname # SGIDchmod 1xxx dirname# Sticky bit
IV. Hidden Permissions
Types of Hidden Permissions:
Managing Hidden Permissions:
chattr
to set hidden permissions:chattr +/- permission filename
lsattr
to view hidden permissions:lsattr filename
V. ACL Permissions
Access Control Lists (ACLs) provide fine-grained permissions for files and directories.
Viewing ACLs:
ls -l
to see if a file has ACL permissions (indicated by a+
at the end).getfacl
to view ACL details:getfacl filename
Setting ACLs:
setfacl
to manage ACLs:setfacl [options] filename/dirname
-m
: Modify ACL.-x
: Remove a specific ACL.-b
: Remove all ACLs.-d
: Set default ACLs.-k
: Remove default ACLs.-R
: Recursively set ACLs.setfacl -m u:st:r file
setfacl -m g:stg:rx file
setfacl -x g:stg file
setfacl -x u:st file
setfacl -b file
setfacl -dm u:user1:rwx,g:user1:rx dir