Open main menu

CDOT Wiki β

Changes

no edit summary
{{Admon/caution|DO NOT USE THIS VERSION OF THE LAB. This page will no longer be updated.|'''New version here:''' https://seneca-ictoer.github.io/ULI101/A-Tutorials/tutorial4<br />'''Andrew's students please go here:''' http://wiki.littlesvr.ca/wiki/OPS145_Lab_4}}
=Data Representation / Numbering Conversion / File Permissions=
:* Manually perform '''numbering conversions''' between the '''decimal''', '''binary''', '''octal''' and '''hexadecimal''' numbering systems<br>(<u>without</u> the use of a computer or calculator)
 
:* Identify '''which numbering system conversion method to use''' when required to perform a numbering conversion
:* Explain the purpose of '''file permissions'''
|- valign="top" style="padding-left:15px;"
|colspan="1" width="22%" |'''Slides:'''<ul><li>Week 4 Lecture 1 Notes:<br> [https://wiki.cdot.senecacollege.ca/uli101/slides/ULI101-4.1.pdf PDF] | [https://ictwiki.cdot.senecacollege.ca/~murrayuli101/slides/ULI101-4.1.pptx PPTX]</li><li>Week 4 Lecture 2 Notes:<br> [https://wiki.cdot.senecacollege.saulca/uli101/slides/ULI101-Week44.2.pdf PDF] | [https://ictwiki.cdot.senecacollege.ca/~murray.saululi101/uli101slides/ULI101-Week44.2.pptx PPTX]<br></li></ul>
| style="padding-left:15px;" | '''Data Representation Definitions:'''
* [https://home.adelphi.edu/~siegfried/cs170/170l1.pdf Data Representation]<br>
* [https://en.wikipedia.org/wiki/Decimal Decimal Numbers]
* [https://en.wikipedia.org/wiki/Hexadecimal Hexadecimal Numbers]<br>
| style="padding-left:15px;"|'''File Permission Concepts:'''
* [https://www.booleanworld.com/introduction-linux-file-permissions/ Introduction to File Permissions]<br><br>
'''File Permission Commands:'''<br>
* [https://ss64.com/bash/chmod.html chmod]<br>
* [https://ss64.com/bash/umask.html umask]<br><br>
|colspan="1" style="padding-left:15px;" width="30%"|'''Instructional Videos:'''* [https://www.youtube.com/watch?v=L2zsmYaI5ww 4nGgqLIKU9U Numbering Conversions]
* [https://www.youtube.com/watch?v=SdgiYoOi0CY File Permissions]
|}
IT professionals may need to perform calculations involving various '''numbering systemsconversion''' to use with<br>to use '''programming functions''' or '''OS commands''' to perform common operations on a computer system.
''IT Professionals that Use Data Representation:''
===File Permissions===
[[Image:listing-file-directory.png|thumb|right|400px|Detailed directory listing showing permissions for a '''directory'''<br>and a '''regular file'''.]]
Since Unix / Linux operating file systems allow for '''multiple user accounts'''<br>it is essential to have a system to '''share''' or '''limit''' access to directories and files contained within the file system.
Since Unix / Linux operating file systems allow for '''multiple user accounts''' it is essential<br>to have a system to '''share''' or '''limit''' access to directories and files contained within the file system.
 
[[Image:listing-file-directory.png|thumb|right|400px|Detailed directory listing showing permissions for a '''directory'''<br>and a '''regular file'''.]]
When '''directories''' and r'''egular files''' are created, they are assigned to an '''owner'''<br>(typically the username which is the creator).
To ''allow'' or ''limit'' '''access''' to those <br>files and directories, those files and directories are assigned to an <br>initial '''group''' referred to as a "'''primary group'''".[[Image:directory-permissions.png|thumb|right|350px|Permissions of a '''directory''' that contain subdirectories and regular files.]]Users that <u>own</u> those ''directories'' and ''regular files'' are referred to as '''users''', users that belong within the <u>same group</u> are referred to as '''same group members''', and those users that do <u>NOT</u> belong to a particular group are referred to as '''other group members'''.
Users that <u>own</u> those ''directories'' and ''regular files'' are referred to as '''users''', users that belong within the <u>same group</u> are referred to as '''same group members''', and those users are do <u>NOT</u> belong to a particular group are referred to as '''other group members'''. '''NOTE:''' In this course, we CANNOT create groups or assign users to groups in the '''Matrix''' server.<br>Instead, you may learn how to those tasks when or if you take a Unix/Linux administration course.<br>On the other hand, you can change which '''user''', '''same group members''' or '''other group members'''<br>can access or NOT access a directory or regular file.<br><br>[[Image:directoryfile-permissions.png|thumb|right|350px|Permissions of a '''directoryregular file''' that contain subdirectories and regular filescontained within a directory.]]
File Permissions consist of '''two-layers''':<br><br>'''First''', the permissions of a '''directory''' that contains regular files, and '''second''', permissions of the ''subdirectories and/or regular files'' within that directory.
A symbol ''dash'' "'''-'''" indicates that the permission has '''NOT''' been granted.
[[Image:file-permissions.png|thumb|right|350px|Permissions of a '''regular file''' contained within a directory.]]The permissions of '''newly-created''' directories and regular files are automatically assigned<br>via a '''user mask''' (we will discuss this shortly). In order to change permissions for <br>directories and regular files, you would use the '''chmod''' command.
'''Changing File Permissions with "chmod" command:'''
[[Image:symbolic-chart.png|thumb|right|550px|Examples of adding, removing and setting permissions using the '''chmod''' command with the '''Symbolic''' method.]]
 
'''<span style="font-style:italic">Symbolic Method:</span>'''
The chmod can use '''symbols''' to ''add'', ''remove'', and ''set'' <span style="font-family:courier;font-weight:bold;">rwx</span> permissions for the '''user''',<br>'''same group members''', and/or o'''ther group members''' for a directory or reqular file.
  <table cellpadding="5" width="70%"br><trbr><th style="border-bottom: 1px solid black;text-align:left;"br>Command</thbr><th style="border-bottom: 1px solid black;text-align:left;">Description</th></tr><tr valign="top"><td width="40%"><span style="font-family:courier;font-weight:bold;">chmod ugo+x script.bash</span></td><td>Add execute permissions to the file '''script.bash''' so it can be run.</tr><tr valign="top"><td><span style="font-family:courier;font-weight:bold">chmod u=rwx,go=x ~</span></td><td>Set "'''pass-thru'''" permissions of your '''home''' directory for same group members and other group members to navigate to other subdirectories (that may have access / view permissions).</tr><tr valign="top"><td><span style="font-family:courier;font-weight:bold;">chmod go-w ~/shared</span></td><td>Remove write permissions for same group members and other group members for the directory '''~/shared'''</td></tr><tr valign="top"><td><span style="font-family:courier;font-weight:bold;">chmod a=rx my</span></td><td>Set read and execute permissions for the directory '''myfile.txt'''</td></tr></table>  
'''<span style="font-style:italic">Octal (Absolute) Method:</span>'''
[[Image:octal-permissions.png|thumb|right|150px|Using octal numbers to represent setting file permissions.]]
Since 1 octal digit represents 3 binary digits, one octal digit can represent the <span style="font-family:courier;font-weight:bold;">rwx</span> permission granted or NOT granted. The permissions '''rwx''' are be in the form of 3 binary digits (1 represents the permission granted and 0 represents the permission NOT granted).
 
 
 
<table cellpadding="5" width="70%"><tr><th style="border-bottom: 1px solid black;text-align:left;">Command</th><th style="border-bottom: 1px solid black;text-align:left;">Description</th></tr><tr valign="top"><td width="40%"><span style="font-family:courier;font-weight:bold;">chmod 500 script.bash</span></td><td>Set read and execute permissions for only the '''user''' for the file '''script.bash''' so it can be run.</tr><tr valign="top"><td><span style="font-family:courier;font-weight:bold">chmod 711 ~</span></td><td>Set "'''pass-thru'''" permissions of your '''home''' directory for same group members and other group members to navigate to other subdirectories (that may have access / view permissions).</tr><tr valign="top"><td><span style="font-family:courier;font-weight:bold;">chmod 750 ~/shared</span></td><td>Set full permissions for user, read and access permissions for some group members and no permissions for other group members for the directory '''~/shared'''</td></tr><tr valign="top"><td><span style="font-family:courier;font-weight:bold;">chmod 555 myfile.txt</span></td><td>Set read and execute permissions for the directory '''myfile.txt'''</td></tr></table>
 
'''NOTE:''' You can use the '''-R''' option to set permissions for directory, subdirectory and directory contents '''recursively'''.
  <table align="right"br><trbr><td>[[Image:umask-directory.png|thumb|right|200px|Setting '''umask''' for newly-created '''directories'''.]]</td><td>[[Image:umask-file.png|thumb|right|200px|Setting '''umask''' for newly-created '''regular files''']]</td></tr></tablebr>
'''Setting Permissions for Newly-Created Directories and Regular Files (umask):'''
<table align="right"><tr><td>[[Image:umask-directory.png|thumb|right|150px|Setting '''umask''' for newly-created '''directories'''.]]</td><td>[[Image:umask-file.png|thumb|right|150px|Setting '''umask''' for newly-created '''regular files''']]</td></tr></table>
The '''umask''' command is used to set the permissions of newly-created directories and regular files.
 
Issuing the '''umask''' command without arguments will display the current umask value.
=INVESTIGATION 1: NUMBERING CONVERSIONS=
<span style="color:red;">'''ATTENTION''': This online tutorial will be required to be completed by '''Friday in week 5 by midnight''' to obtain a grade of '''2%''' towards this course</span><br><br>
For this investigation, we will NOT be logged into our Matrix account, but it is recommended to have sheets of paper available<br>or an '''MS Word document '''<br>open to manually perform numbering conversions.
<span style="color:blue;">'''NOTE:''' It is essential that you learn how to <u>manually</u> perform numbering conversions since you will NOT be permitted to perform quizzes, midterm, or your final exam with a computer or a calculator. Learning to quickly perform manual numbering conversions will make IT professional more productive such as setting permissions, designing computer networks, or selecting complex colors when developing webpages.</span>
[[Image:calc-check.png|thumb|right|200px|Only use a calculator to check your numbering conversion '''AFTER''' you have performed the operation '''manually'''. ]]
You will now get practice performing numbering conversions.
 
'''Perform the Following Steps:'''
# Let's convert the following ''8-bit'' binary number '''10111110''' to a '''<u>decimal number</u>'''.<br><br><span style="color:blue;">'''NOTE:''' It is important to learn and '''memorize''' the '''correct techniquesmethods''' to perform the<br>proper numbering conversion method (i.e. view '''method 1''' above (drawing the L's).</span><br><br># Write the manual conversion either in your MS Word document or on a sheet of paper.<br><br># Use a '''calculator''' to check your work. In MS Windows, you can set the calculator to Programming mode<br>by making the selection to '''binary''', enter the binary number '''10111110''' and view the decimal equivalent.<br><br>Did you get the correct answer? If not, <u>retry </u> the method and check to see what you did wrong.<br><br># Perform a manual conversion of the '''decimal number 55''' to an a '''<u>8-bit binary number</u>'''.<br>What method (displayed above) will you use? Use a calculator to check your work.<br><br># Perform a manual conversion of the '''octal number 461''' to an a '''<u>8-bit binary number</u>'''.<br>What method (displayed above) will you use? Use a calculator to check your work.<br><br># Perform a manual conversion of the '''8-bit binary number 11110001''' to a '''<u>hexadecimal number</u>'''.<br>What method (displayed above) will you use? Use a calculator to check your work.<br><br># Perform a manual conversion of the '''hexadecimal number ABC''' to an a '''<u>8-bit binary number</u>'''.<br>What method (displayed above) will you use? Use a calculator to check your work.<br><br>
# Perform a manual conversion of the '''binary number 10101111''' to an '''<u>octal number</u>'''.<br>What method (displayed above) will you use? Use a calculator to check your work.<br><br>
# Perform a manual conversion of the same '''binary number 10101111''' to a '''<u>hexadecimal number</u>'''.<br>What method (displayed above) will you use? Use a calculator to check your work.<br><br>
[[Image:file-permission-practice-1.png|right|250px|thumb|]]
In this sectioninvestigation, you will get experience using the '''chmod''' and command to '''umaskchange permissions''' commands<br>to for <u> existing</u> files and the using '''change permissionsumask''' command to automatically set permissions<br>for '''directories''' and '''<u>newly-created</u> files'''.
# '''Login''' to your matrix account and issue a command to '''confirm''' you are located in your '''home''' directory.<br><br>
# Issue a single Linux command to create the following directory structure displayed in the diagram to the right.<br><br>'''NOTE:''' You will now run a shell script to confirm that you properly created that directory structure<br>in your ''Matrix'' account.<br><br>
# Issue the following Linux command to run a checking script:<br><span style="color:blue;font-weight:bold;font-family:courier;">bash /home/murray.saul/scripts~uli101/week4-check-1</span><br><br># If you encounter errors, make corrections and '''re-run''' the checking script until you <br>receive a congratulations message, then you can proceed.<br><br>[[Image:file-permission-practice-2.png|right|450px|thumb|]]# Issue Linux commands to create '''<u>empty</u> files''' for each of those newly created '''directories ''' as show shown in diagram to the right:<br><br>'''NOTE:''' You will now run another shell script to confirm that you properly created those empty files within those specified directories.<br><br># Issue the following Linux command to run a checking script:<br><span style="color:blue;font-weight:bold;font-family:courier;">bash /home/murray.saul/scripts~uli101/week4-check-2</span><br><br># If you encounter errors, make corrections and '''re-run''' the checking script until you <br>receive a congratulations message, then continue the remaining steps.<br><br>Let's get practice understanding '''viewing permissions''', '''changing permissions''', and <u>automatically</u> '''setting your Linux account to automatically set permissions for newly created directories and regular files'''.<br><br># Issue the following Linux commands:<br><span style="color:blue;font-weight:bold;font-family:courier;">ls -ld ~/documents ~/clients ~/vendors<br>ls -lR ~/documents ~/clients ~/vendors</span><br><br>'''NOTE:''' You should see permissions already set for those newly created directories and regular files. <br>What do these permissions mean for '''same group member''' and '''other group member''' access to those directory and regular files?<br><br># Let's limit access to the '''clients''' and '''vendors''' directories to only yourself and same group members. <br>Issue the following Linux command:<br><span style="color:blue;font-weight:bold;font-family:courier;">chmod 750 ~/clients ~/vendors</span><br><br># Issue the '''ls-ld''' command and '''ls -lR''' commands (as you did in ''step #8'') to confirm that the permissions for those directories have been changed.<br><br>'''NOTE:''' The '''-R''' option for the '''chmod''' command can change the file permissions <u>recursively</u> within a directory structure.<br><br>
# Issue the following Linux command: <span style="color:blue;font-weight:bold;font-family:courier;">chmod 750 -R ~/documents</span><br><br>
# Again, use Issue the '''ls-ld''' command to confirm the permissions for the <br>'''~/documents''', '''~/document/memos''' , '''~/documents/reports''', and '''~/documents/contracts''' directories.<br><br># Issue the following Linux command: <span style="color:blue;font-weight:bold;font-family:courier;">ls -lR ~/documents</span><br>What do you noticed happened to the permissions for the regular files contained in those directories.<br>Did those regular file permissions change?<br><br>We want to will now change those permissions for regular text file permissions contained in subdirectories<br>of the '''documents''' directory to the following settings: <span style="font-weight:bold;font-family:courier;">r w - r - - - - -</span><br><br># Issue the following Linux commands: <br><span style="color:blue;font-weight:bold;font-family:courier;">chmod 640 ~/documents/memos/memo*.txt<br>chmod 640 ~/documents/reports/report*.txt<br>chmod 640 ~/dcoumentsdocuments/contracts/contract*.txt</span><br><br># Issue the '''<span style="font-weight:bold;font-family:courier;">ls -lR''' </span> command for the '''~/documents''' directory to confirm that those regular file permission have changed.<br><br>Let's run a checking script to make certain you correctly set permissions for those directories and files.<br><br># Issue the following: <span style="color:blue;font-weight:bold;font-family:courier;">~uli101/week4-check-3</span><br><br># If you encounter errors, make corrections and then re-run the checking script until you receive a congratulations message<br>and then continue with this tutorial.<br><br>Let's get some practice setting permissions to allow users to make editing changes to regular files.<br><br>
# Issue the following Linux command: <span style="color:blue;font-weight:bold;font-family:courier;">chmod ugo-w ~/documents/memos/memo*.txt</span><br><br>
# Use the '''<span style="font-weight:bold;font-family:courier;">ls''' </span> command to verify that those regular file's permissions have changed.<br><br># Using the nano or vi text editor, open the regular file '''~/documents/memos/memo1.txt''', <br>and type in some text and try to save your editing changes.<br>What happened?<br><br># To <u>'''abort '''</u> your editing session in '''vi, ''': type <span style="color:blue;font-weight:bold;font-family:courier;">:q! </span> and to press '''ENTER'''.<br>To <u>'''abort '''</u> your editing changes in '''nano, just ''': type <span style="color:blue;font-weight:bold;font-family:courier;">ctrl-x</span><br>type <span style="color:blue;font-weight:bold;font-family:courier;">n </span> and then press '''ENTER''' when prompted to save editing changes.<br><br># Issue the following Linux command to add write permissions for all files in the '''memos ''' directory <br>for yourself (i.e. user): <span style="color:blue;font-weight:bold;font-family:courier;">chmod u+w ~/documents/memos/*</span><br><br># Repeat steps to edit the previous file '''~/documents/memos/memo1.txt''' (as you did in ''step #1920'').<br>Were you able to edit the file and save your editing changes?<br><br># Issue a Linux command to view the <u>contents</u> of the '''~/documents/memos/memo1.txt'''<br>text file that you were able to edit. What happened?<br><br># Issue the following Linux command to view permissions for your '''home''' directory: <span style="color:blue;font-weight:bold;font-family:courier;">ls -ld ~</span><br><br>What does execute permissions mean for same group members and other group members <br>in terms of your '''home''' directory?<br><br>
# Issue the following Linux command to create a new subdirectory: <span style="color:blue;font-weight:bold;font-family:courier;">mkdir ~/shared</span><br><br>
# Issue the following Linux command: <span style="color:blue;font-weight:bold;font-family:courier;">ls -l ld ~/shared</span><br><br>What are the permissions for this newly-created directory?<br>Can other users access the directory pathname '''<span style="font-family:courier">~youruserid/shared</span>''' ?<br><br>
# Issue the following Linux command (without an argument): <span style="color:blue;font-weight:bold;font-family:courier;">umask</span><br><br>'''NOTE:''' You should see a '''four-digit octal''' number. Drop the leading zero on the left to obtain the '''default umask value'''.<br><br>
# Perform a '''mathematical calculation''' by taking the octal number '''777''' and <u>subtracting </u><br>the default umask value you determined in the previous step.<br>What is the result?<br><br>
# Convert that octal number result to a '''binary''' number. What does that represent as newly created directory permissions?<br>Does that correspond to the permissions for the newly created '''~/shared''' directory?<br><br>
# Repeat '''steps #27''' and '''the calculation (like in step #28''' to see how ) but with a umask setting of '''077''' to see how this new umask setting would <br>affect permissions of newly-created directories.<br><br>
# Issue the following Linux command: <span style="color:blue;font-weight:bold;font-family:courier;">umask 077</span><br><br>
# Issue the following Linux command (without arguments): <span style="color:blue;font-weight:bold;font-family:courier;">umask</span><br><br>NOTE: You should notice the value '''0077'''. By dropping the leading zero to the left, <br> that would provide the default '''umask value of 077'''.<br><br>
# Issue the following Linux command: <span style="color:blue;font-weight:bold;font-family:courier;">mkdir ~/shared2</span><br><br>
# Issue the following Linux command: <span style="color:blue;font-weight:bold;font-family:courier;">ls -ld ~/shared2</span><br><br>Do the permissions for this newly created directory match the predicted permissions that you calculated in '''step #2930'''?<br><br># Issue the following Linux command to create an empty regular file called '''myfile.txt''' in the '''~/shared2''' directory: <br> <span style="color:blue;font-weight:bold;font-family:courier;">touch ~/shared2/myfile.txt</span><br><br># Use the '''<span style="font-weight:bold;font-family:courier;">ls -l''' </span> command to view the permissions for this newly created regular file.<br><br>What do you notice about those permissions?<br><br>Let's run a checking script to make certain you correctly set permissions for those recently-created directories and files.<br><br># Issue the following: <span style="color:blue;font-weight:bold;font-family:courier;">~uli101/week4-check-4</span><br><br>If you encounter errors, make corrections and then re-run the checking script until you receive a congratulations message<br>and then continue with this tutorial.<br><br>
# Logout of your Matrix account, and then log-back into your Matrix account.<br><br>
# Issue the following Linux command (without arguments): <span style="color:blue;font-weight:bold;font-family:courier;">umask</span><br><br>What happened? Referring to your notes, what do you need to do to make that umask value persistent?<br><br># After <span style="color:red;">'''WARNING''':<br>You should be <u>extremely</u> aware of your permissions since you complete the Review Questions sections to get additional practice, then may perform '''marked work ''' for <u>other</u> courses on your '''online assignment 2Matrix'''server.<br>and complete the sections You should NOT set permissions to share your work with '''same group''' or '''1other group''' and members (unless given '''2specific permissions instructions from your course professors''' labelled: ). If students can have access to your directories and project files, they could '''Practice Using The vi Text Editorcopy''' your work and thus make yourself and other student(s) that copied your work to be charged with '''Permissionsacademic dishonesty''' respectively.</span><br><br>: Complete the Review Questions sections to get additional practice.<br><br>
= LINUX PRACTICE QUESTIONS =
The purpose of this section is to obtain extra practice to help with your assignment #1, quizzes, your midterm, and your final ezamexam.
Here is a link to the MS Word Document of ALL of the questions displayed below but with extra room to answer on the document to
simulate a quiz:
https://ictwiki.cdot.senecacollege.ca/~murray.saululi101/uli101files/uli101_week4_practice.docx
Your instructor may take-up these questions during class. It is up to the student to attend classes in order to obtain the answers to the following questions. Your instructor will NOT provide these answers in any other form (eg. e-mail, etc).
[[Image:number-conversion-chart.png|right|450px|thumb|]]
'''Review Questions:'''
# Write a simple chart to show which values are represented for letter '''A - F''' for a hexadecimal number.
# How many '''binary''' digits does 1 octal digit represent?
# How many '''binary''' digits does 1 hexadecimal digit represent?[[Image:number-conversion-chart.png|right|450px|thumb|]]
# Use '''manual numbering conversion''' to complete the table displayed to the right.
<span style="font-family:courier;font-weight:bold">chmod u=rwx,go=x ~/linux/content</span><br>What would be the new permissions for the “'''content'''” directory?<br><br></li><li>Assume that you just issued the commands:<br><span style="font-family:courier;font-weight:bold;">umask 077<br>mkdir mydir<br>touch mydir/myfile.txt<br></span><br>What would be the permissions for the newly created '''directory''' and '''regular file'''?<br>(show your work)
</li></ol>
 
 
 
_________________________________________________________________________________
 
Author: Murray Saul
 
License: LGPL version 3
Link: https://www.gnu.org/licenses/lgpl.html
 
_________________________________________________________________________________
 
[[Category:ULI101]]