This is the 9th day of my participation in the August Wen Challenge.More challenges in August

Chwon Changes the file owner

The Linux chown (change owner) command is used to set a file owner and a file associated group. Linux/Unix is a multiplayer operating system where all files are owned. Chown is used to change the owner of a specified file to a specified user or group. The user can be a user name or a user ID, and the group can be a group name or a group ID. The file is a list of files whose permissions are to be changed separated by Spaces. .

Chown requires the permission of the root user to run this command.

== Only super users and file owners in a file group can change a file association group. Non-superusers may need to run the CHGRP command to set up a gateway group. = =

Permission: root

Grammar:

chown [-cfhvR] [--help] [--version] user[:group] file...
Copy the code

Parameters:

  • User: indicates the user ID of the new file owner
  • Group: user group of the new file owner
  • -c: Displays information about the changed part
  • -f: Ignores error information
  • -h: Restores symbolic links
  • -v: displays detailed processing information
  • -r: processes all files in the specified directory and its subdirectories
  • –help: Displays auxiliary instructions
  • –version: Displays the version

Example:

Root: chown root /var/run/httpd.pid Chown runoob:runoobgroup file1. TXT # set the owner of all files and subdirectories under the current directory to runoob. Chown -r runoob:runoobgroup * # set the associated group of /home/runoob to 512 without changing the owner: chown :512 /home/runoobCopy the code

CHGRP Changes the group to which a file belongs

The Linux CHGRP (full: change group) command is used to change the owning group of a file or directory. Unlike the chown command, CHGRP allows an ordinary user to change the group to which a file belongs, as long as the user is a member of that group. In the UNIX family of systems, control of file or directory permissions is managed by owner and group. You can use the CHGRP command to change the owning group of a file or directory by using the group name or group id.

Grammar:

CHGRP [-cfhrv][--help][--version][Group][File or directory... Or the CHGRP [- cfhRv] [-- help] [-- the reference = > < reference file or directory] [-- version] [...] file or directoryCopy the code

Parameter Description:

  • -c or –changes works like the “-v” argument, but only returns the changes.
  • -f or –quiet or –silent No error information is displayed.
  • -h or –no-dereference only modifies symbolic linked files without changing any other related files.
  • -r or –recursive processing, processing all files and subdirectories in the specified directory at once.
  • -v or –verbose displays the command execution process.
  • –help Online help.
  • –reference=< Reference file or directory > Sets the owning group of the specified file or directory to be the same as that of the reference file or directory.
  • –version Displays version information.

Example:

// Modify Change the log2012. Log file from root group to bin group
[root@localhost test]# chgrp -v bin log2012.log
"log2012.log"The owning group of the// Change the owning group of log2012.log by referring to the owning group of the log2013.log file
[root@localhost test]# ll
---xrw-r-- 1 root bin  302108 11-13 06:03 log2012.log
-rw-r--r-- 1 root root     61 11-13 06:03 log2013.log
[root@localhost test]#  chgrp --reference=log2012.log log2013.log 
[root@localhost test]# ll
---xrw-r-- 1 root bin  302108 11-13 06:03 log2012.log
-rw-r--r-- 1 root bin      61 11-13 06:03 log2013.log
Copy the code

Umask Specifies the default permission to initially create a directory or file.

  1. For directories, x permission means access to the directory, so there is no problem with initial assignment of this permission; == The permission of the directory is 777==
  2. For file x permission on behalf of execution, this risk is too high, so the general permission initial assignment must be removed from X; == The permission of the file is 666==
[root@www ~]# umask
0022
Copy the code
  • The first 0 represents the permissions discarded by suID;
  • The second 0 indicates that the file/directory owner has not discarded any permissions (except x permissions if it is a file, why read the above explanation);
  • The third 2 indicates that the user group for this file/directory has discarded its W permission (and its X permission if it is a file);
  • The third 2 indicates that the only permissions available to other users of this file/directory are R and X (except files).

The default creation permissions of the root user are different from those of other users.

How to calculate the default permissions? The following uses user root as an example

// The default permission for creating folder temp is RWX r-x and r-x is 755
 777All permissions -022Discard permissions ---- subtraction755The default permissions// The default permission for file aaa creation is rw-r -- r-- 755
 Awesome!Why are all permissionsAwesome!Because the file created does not have the execute permission, the risk is too high022Discard permissions ---- subtraction644The default permissionsCopy the code

== You can use umask to change the default value of 0022 to another value, and then subtract all permissions to create folders and directories by default. But it is not recommended to make changes. = =