Because shell scripts are a collection of many commands, these commands may involve manipulating a file, and the execution of the shell script requires the current user to have permission to run the script, otherwise it will fail because of insufficient permissions.
The commands in Linux that involve permissions are: chmod, ACLs, Sudo, and the following one by one explain their respective usage.
chmod: Used to assign permissions in a very high frequency.
When assigning permissions, there are two commonly used forms, one is to use the octal three digits to specify all the permissions of the file (Owner,group,other), one is to use the shorthand of a class of users, append a +/-, and then add the permissions to be assigned or retracted.
[Email protected]:/# echo ' echo ' Hello World ' > Test.sh[email protected]:/# ls-l test.sh-rw-r--r--1 root root 19 January c0/>14 11:10 test.sh[email protected]:/#./test.shbash:./test.sh:permission denied[email protected]:/# chmod 744 Test.s H[email protected]:/#./test.shhello world[email protected]:/# su ubuntu[email protected]:/$ ls-l test.sh-rwxr--r--1 roo T Root 19 January
Note that only the owner of the file can make changes to the file's permissions, and the file permissions cannot be changed even if other users have RWX permissions on the file.
Another form:
[Email protected]:/# echo ' echo ' Hello World ' > Test.sh[email protected]:/# ls-l test.sh-rw-r--r--1 root root 19 January
Above a form, the allocation of permissions is more intuitive, because to what kind of user assigned what permissions, at a glance, do not need to calculate. where the owner uses U, the group user uses G, and the other user uses O,a to represent all users.
The more secure way to assign permissions is to assign a file's group user permission to read and write, and then add some other user to the group. Otherwise, if the other assignment permissions can not be broken down, for example, I only want to assign write permissions to the other 6 users, then I can not assign W permission, because once the W, all other has W permission.
Shell Script--permission assignment