The incident

One day, Pupuu contacted server resource deployment for the first time and found that the newly uploaded test script did not have execution permission. Question:

  • 1. In the same project, git pulled down, why do other files have execution permission, this file does not.
  • 2. Is there any way to specify a directory

So, go to the local run, found that there is no local permission, chmod add permission, go to the server to pull the code can also be executed.

  • Therefore, git pulls down files with the same execution permissions as when they were committed.
  • So, the above question evolved into, what is a quick way to create a file with execution permission.

Research conclusion

After a round of Googling, the following conclusions emerged:

  • 1. Set umask to modify the default permissions of newly created files
  • 2. Unfortunately, Linux does not allow direct execution of newly created files
  • 3. After a new file is created, chmod can modify the permission. After that, the server does not need to change permissions on files submitted by Git.

Linux Permission tips

field

-rwxr--r--

First digit (file/folder) The user u Group of users g Other Users O
-/d rw- r– r–

chmod

  • chmod u+w filename -> -rwxr--r--
  • chmod u=rwx,go+x filename -> -rwxr-xr-x

umask

  • Umask is the exact opposite of chmod, setting permission complement (remove permissions)
  • Maximum permission 7=4+2+1
  • The default umask is 022, folder permissions 755, file permissions 644 (-rw-r--r--)
  • Change the umask command to set complement 000 (highest permission, folder 777, file 666)-rw-rw-rw-)

umask 000