Common Linux commands (version 2)-permission management commands
Permission management commands
1. chmod [change the permissions mode of a file]:/bin/chmod
Syntax: chmod [{ugo} {+-=}{ rwx}] [file or directory name] // intuitive
E.g. chmod u + wx filename
Chmod o-x filename
Chmod g = rwx filename
Or: chmod [mode = 421] [file or directory] // recommended
Number of the permission pair:
R-4
W-2
X-1
E.g. rwxr-xr -- 754
Rw-r-x -- x 651.
752 rwxr-x-w-
Chmod 777 dir1 // set the directory dir1 to have all permissions for all users
Appendix: su [-] username: users that can be switched // experiment content
Exit: exit
Summary:
Directory:
R-ls
W-rm, touch, mkdir
X-cd
[Therefore, in Linux, basically all directories have the rx permission. Otherwise, it would be more awkward...]
2. chown [change file ownership]/bin/chown
Chown [user] [file name or directory name] # change the file owner
E.g. chown nobody file1 # change the owner of file file1 to "nobody" and "nobody" to the default user.
Appendix-Add a user:
1) useradd afang
2) passwd afang # set a password for the passwd
3. chgrp [change file group ownership]/bin/chgrp
Chgrp [user group] [file or directory] # change the group to which the file or directory belongs
# Must be an existing system group
E. g. chgrp adm file1 # change the file1 group to adm.
# Adm is an existing group in the system.
[How do I use a group to change the user group? Let's study later...]
4. umask/bin/umask # display and set the default file permissions
Umask [-S] //-S displays the default permissions of new files or directories in the form of rwx, which is more intuitive.
E.g. umask // view the default permissions.
# Display 0022: 0-Special Permission bit, 022-user permission bit [u, o], representing the mask value;
Calculation: 777-022 = 755 // This is the default permission for creating a directory
666-022 = 644 // is the default permission for creating a file, which does not have the x permission. The File Permission is less than the directory permission. X
Appendix 1: many UNIX systems do not have the-S option, so they can only be calculated based on the above!
Appendix 2-Linux permission rules: default file creation, cannot grant executable permissions (X )! The advantage is that it shields many attacks and viruses.
Appendix 3-change default permission value: umask [mask value] // The Mask value must be calculated first, instead of the initial permission value. It must be the calculated mask value, but do not change it!