lab5.docx
Document Details
Uploaded by StylishSpessartine
University of Science and Technology
2024
Tags
Full Transcript
**University of Science and Technology** **Faculty of Computer Science and Information Technology** **Open Source Operating Systems** **Lab (5) Date 01-05-2024** **Description:** Students are able to know what is user, types of user, and types of permissions, Numerical permissions, symbolic per...
**University of Science and Technology** **Faculty of Computer Science and Information Technology** **Open Source Operating Systems** **Lab (5) Date 01-05-2024** **Description:** Students are able to know what is user, types of user, and types of permissions, Numerical permissions, symbolic permissions, applying permissions on folder, user privileges etc in this experiment, umask command. **Lab Learning Outcomes:** Introduction to user and group permissions. **Lab Instructions:** The lab instructor has to follow the steps below to demonstrate to the students how to change and set files permissions using chmod and umask commands. 1. **Managing File and Directory Permissions** - Permissions specify who can access a file or directory, and the types of access. - Every file and directory in a Linux system contains information regarding permission in its inode. - The section of inode that stores that stores permission is called the mode. - The mode of the file is divided into three sections: - Three types of access permissions can be assigned to file or directory - The root user has permission to every file and directory regardless of what mode of file and directory indicates 2. **Permissions on Files:** A permission represents an action that can be done on the file: 3. **The Structure of Mode for Directory** 4. **Permissions on directories** 5. **Examining Permissions:** **Output**: 1. Specify Permissions using chmod command 2. Set the file Permissions using letters in the following format: \$ chmod \[ugoa\]\[+=-\]\[rwxX\] - The first letters indicate who to set permissions for: u for the file's owner, g for the group owner, o for other users, or a for all users. - = sets permissions for files, + adds permissions to those already set, and -- removes permissions. - The final letters indicate which of the r, w, x permissions to set. - Or use capital X to set the x permission, but only for directories and already-executable files. **Examples:** 1. make file1.txt readable, writable, and executable to the user, readable to the group, and nothing to the world, this could be done with: **\$ chmod u=rwx,g=r,o= file1.txt** 2. Let all files.txt readable, writable access for the owner, readable, and writable access for the group and readable access for the others. \$ chmod ug=rw,o=r \*.txt **Output**: \$ ls -l **-rw-rw-r\--** 9 aaronc staff 4096 Oct 12 12:57 file1.txt **-rw-rw-r\--** 9 aaronc staff 4096 Oct 12 12:57 file2.txt **-rw-rw-r\--** 9 aaronc staff 4096 Oct 12 12:57 file3.txt 7. **Changing the Permissions of a Directory and Its Contents** A common requirement is to change the permissions of a directory and its contents. chmod accepts a -R option: **Example:** Change the permissions for public-directory and it's contents \$ chmod -R g+rwx,o+rx public-directory **Output**: \$ ls -l public-directory 8. **Digital Representation of Access Permission** Read = 2 ^2^ = 4 Write = 2 ^1^ = 2 Execurte =2 ^0^=1 3. Let file1.txt readable, writable, and executable access for the owner, readable, and executable access for the group and no access for the others. \$ chmod 750 file1.txt **Output**: \$ ls -l file1.txt **-rwxr-x\-\--** 9 aaronc staff 4096 Oct 12 12:57 file1.txt 4. Let all files.txt readable, writable access for the owner, readable, and writable access for the group and readable access for the others. \$ chmod 664 \*.txt **Output**: \$ ls -l **-rw-rw-r\--** 9 aaronc staff 4096 Oct 12 12:57 file1.txt **-rw-rw-r\--** 9 aaronc staff 4096 Oct 12 12:57 file2.txt **-rw-rw-r\--** 9 aaronc staff 4096 Oct 12 12:57 file3.txt **Example**: \$ chmod 777 file1 Full permissions for owner, Group and others. 9. **Managing the ownership from th e command line:** - **Changing the owner of a file:** Every file has an owner, usually the person who create it. To become an owner of a file that belongs to previously to another user you have to make a copy of the file. For example: \$ cp /home/ali/contents contents Makes you the owner of the copy version of the file contents, which belongs to ali. A more simple and direct way to change the owner of a file is to use the chown command. But only the owner of the file or the super user can use the command. **Example**: \$ chown Mohammed file1 Mohammed will be the owner of file1. - **changing the group of a file:** To change the group of the file belongs to you, you can use the command chgrp **Example**: \$ chgrp group2 file1 group2 will be the new group of file1. only the owner of the file or the super user can change the file group. 10. **Using umask to set permissions:** umask command allows you to specify permissions of all files created after you issue (execute) umask command. umask uses a numeric octal code for representing permissions ( 777 full permissions). you specify your permissions by telling umask what to subtract from the full permission. **Example:** Write the command that make All new files will have the permissions : rwxr-xr-x. 1. Count the targeted permission: rwx r-x r-x 7 5 5 2. Subtract the targeted permission from the full permission Full permission 777 ------------------- ----- Target permission 755 Umask 022 3. Run the command : \$ umask 022 - To make your umask executed automatically you have to put the umask command in your.bash\_profile file (created by the OS for every user). - **Task** \$ vi.bash\_profile To make your umask executed automatically.