Linux File Permissions and Ownership
chmod (Change File Permissions)
File permissions are associated with three distinct user groups:
- Owner: The user who created the file or directory.
- Group: A group of users who share common access permissions to the file or directory.
- Others: All other users who are not the owner or part of the group.
The chmod command is used to change the permissions (read, write, execute) of files and directories. The command is followed by a octal code or symbolic representation that specifies the desired permissions. See the example below:
chmod 644 filename.txt
An example of making a script that is only executable, readable and writable by the owner would be below:
chown (Change File Ownership)
The chown command is used to change the ownership of files and directories. It can change both the owner and group owner of a file.
In the example above, the file restricted_script.sh script cannot be run by our user because its owner by the root user and has restrictive permissions. The change this, we should SU (switch user) to the root user, and chown the script back to our user account.
__
Be sure to update the chown command below with your username:username. My username and group is paulh:paulh, but yours likely is different.
Once we chown the file back to our user account, we can exit the root user and execute the script:
# Switch to root user…
No comments yet. Add the first comment to start the discussion.