In the Linux environment, the execution of the executable program encounters a Permission denied solution

In the Linux environment, the execution of an executable program encounters Permission denied because the executable program does not have the "execute" permission.

1. Can be confirmed by "ls -al" command

Taking what I encountered as an example, you can see that play_test does not have execution permission (x)

ls -al
-rw-r--r--    1 idtv     idtv         82656 Apr  5 20:43 play_test

2. "chmod 777 play_test" change play_test permission

Check the permissions again, which already includes execution permissions (x)

-rwxrwxrwx    1 idtv     idtv         82656 Apr  5 20:43 play_test

That's it for execution.

3. By the way, record the file permissions of linux file and the usage of chmod

Take the file permissions of play_test as an example to explain,

- rwx rwx rwx      play_test

-Indicates that play_test is a file, not a directory, if it is a directory, - will become d(directory)

Red rwx indicates that the owner's permission is read+write+execute

Blue rwx indicates that the permission of the group to which it belongs is read+write+execute

Green rwx indicates that other (other) permissions are read+write+execute

The order in which the user obtains file permissions: first check whether the user is the owner, if yes, then ignore the subsequent permissions; then check whether the user belongs to the group, if yes, then ignore the latter permissions; if it is other, then look at other permissions.

In addition to the above character representation, the authority can also be represented by numbers

4 stands for read (r) permission

2 stands for write (w) permission

1 stands for execute (x) permission

Therefore, when trying to modify file permissions, you can use characters or numbers, such as:

chmod 777 play_test ==> means that User/Group/Other have read + write + execute permissions

chmod =rwx,=rwx,=rwx play_test==>That is, User/Group/Other have read + write +execute permissions

4. How to use chmod

BusyBox v1.34.1 (2023-03-16 17:24:17 CST) multi-call binary.

Usage: chmod [-Rcvf] MODE[,MODE]... FILE...

MODE is octal number (bit pattern sstrwxrwxrwx) or [ugoa]{+|-|=}[rwxXst]

        -R      Recurse
        -c      List changed files
        -v      Verbose
        -f      Hide errors

#ls -al
-rwxrwxrwx    1 idtv     idtv         82656 Apr  5 20:43 play_test
原始权限

#chmod =-r--r--r-- play_test
--wx-wx-wx    1 idtv     idtv         82656 Apr  5 20:43 play_test
执行后,相当于少了r 权限

#chmod =-r--,=r--,=r-- play_test
-r--r--r--    1 idtv     idtv         82656 Apr  5 20:43 play_test
执行后,相当于User/Group/Other最终权限是read

#chmod 777 play_test
-rwxrwxrwx    1 idtv     idtv         82656 Apr  5 20:43 play_test

The usage habit is that the mode uses numbers, such as the above "chmod 777 play_test"

If the permission of the directory is changed, you need to add -R, "chmod -R 777 directory"

umask 

In addition to the chmod command, there is also the umask command to change permissions. The role of umask is to "cancel" the corresponding permissions and affect the default permissions of "new" created files and directories. What chmod changes is the permissions of existing directories and files.

Under the shell console, the umask command will list 4-digit octal numbers, for example,

#umask

0000

The umask value is 000, and the file created by this user has (666-000)=666 octal permission, which is equivalent to the following string:

-rw-rw-rw-

因为新创建的文件是不能有执行权限的,因此新建文件默认是666(read+write)

umaskA value of 0245 means that the newly created directory has (777-0245)=0532 octal permission, which is equivalent to the following string:

dr-x-wx-w-

The newly created directory has execution permission, and the execution permission of the directory can be entered, that is, the cd command can enter this directory.

rwx permissions, there are differences between files and directories, the differences are as follows,

document

 r:读取文件内容
 w:修改文件内容
 x:执行程序(执行权限对除二进制程序以外的文件没什么意义)

Table of contents

r:查看目录下的文件列表 
w:删除和创建目录下的文件
x:可以cd进入目录,能查看目录中文件的详细属性,能访问目录下文件内容(基础权限)

Guess you like

Origin blog.csdn.net/dreamDay2016_11_11/article/details/130502233