Shell Script--permission assignment

Source: Internet
Author: User
Tags file permissions

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.