1,234
edits
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/tutorial1<br />'''Andrew's students please go here:''' http://wiki.littlesvr.ca/wiki/OPS145_Lab_1}}=ABOUT USING YOUR MATRIX SERVER ACCOUNT=[[Image:vmware-1a===Main Objectives of this Tutorial===* Learn how to access your '''Matrix''' server account (from home and/or from Seneca computer lab).png|thumb|right|450px|The VMware Workstation 12 application will allow you * Learn several ways to create '''exit''' your Matrix Linux Account session.* Understand the '''Linux command structure''' and administer how to get '''help''' with Linux command usage.* Become efficient with '''Linux command line editing''' by using '''short-cut keys'''.* Issue a '''4 different virtual machineschecking program''' (i.e. ''Shell Script'VM') to '''s) on confirm''' that you accessed your computer systemMatrix account. ]]===Purpose of Having a Matrix Account===* Perform '''LINUX PRACTICE QUESTIONS''' for additional practice.
|colspan="2" style="font-size:16px;font-weight:bold;border-bottom: thin solid black;border-spacing:0px;"|Course Notes / Software<br>
|- valign="top" style==Main Objectives==="padding-left:15px;"
| style="padding-left:15px;" |'''Matrix Account Access:'''* Note common Linux commands [https://ss64.com/bash/logout.html logout , exit]<br>*[https://www.quora.com/What-is-the-difference-between-typing-Ctrl+C-and record them -Ctrl+D-in your lab1 logbook-the-Linux-terminal <ctrl><d>]*[http://man7.org/linux/man-pages/man1/passwd.1.html passwd]<br>'''Command Line Editing:'''*[https://www.ostechnix.com/list-useful-bash-keyboard-shortcuts/ Bash Shell Shortcut Keys]<br>| style="padding-left:15px;"|'''General Linux Commands:'''*[http://man7.org/linux/man-pages/man1/pwd.1.html pwd]<br>*[http://man7.org/linux/man-pages/man1/cd.1p.html cd]<br>*[http://man7.org/linux/man-pages/man1/ls.1p.html ls]<br>*[http://man7.org/linux/man-pages/man1/cal.1.html cal]<br>*[http://man7.org/linux/man-pages/man1/date.1.html date]<br>*[http://man7.org/linux/man-pages/man1/who.1.html who] , [http://man7.org/linux/man-pages/man1/w.1.html w]<br>*[http://man7.org/linux/man-pages/man1/whoami.1.html whoami ,who am i]<br>*[http://man7.org/linux/man-pages/man1/clear.1.html clear , <ctrl><l>]<br>
|}
= KEY CONCEPTS=
{|colspanwidth="3100%" stylecellspacing="font-size:16px;font-weight:bold;border-bottom: thin solid black;border-spacing:0px;padding-left:15px;0"|Linux Command Reference<br>
|- valign| style="toppadding-left:0px;width:10%" |'''learn.senecacollege.ca'''| style="padding-left:15px;width:65%"|Learning Content Management System (''Link to Resources'' / ''Student Grades'' / ''Online Quizzes'')
| -|[[Imagestyle="padding-left:ssd0px;width:10%" |'''wiki.cdot.png|thumbsenecacollege.ca'''|style="padding-left:15px;width:65%" |175px|<b>Solid State Drive<''Lecture Notes'' / ''Tutorials'' (weekly, review) / ''Practice Questions'' /b><br>Minimum Size: 250GB]]''Additional Learning Resources''
| [[Image:log-book.png|thumb|style="padding-left:0px;width:10%" |100px|'''<bspan style="color:blue;">[[:Media:OPS235_logbookmatrix.senecacollege.pdf|Lab Logbook]]ca</bspan><br>(lab 1)]]'''| style="padding-left:15px;width:65%" |Matrix is our Linux server environment used for "''hands-on practice''". Each ULI101 student has an account on this server.
|}
===Layout of the Matrix Linux Server===
[[Image:matrix-layout.png|thumb|right|250px|The Matrix server consists of several Computers connected together to form a '''cluster'''. A '''Linux Cluster''' is a '''cost effective''' alternative to larger servers. ]]
The '''Matrix server''' consists of '''several computers connected together''' to form a '''cluster'''.<br>A '''Linux cluster''' is a '''cost effective''' alternative to buying larger servers.
All registered students in this course should have an account on the Matrix server.<br>You will be using this account for the following reasons:
:* Issuing '''Linux commands''':* Becoming productive using the Linux '''command prompt''' ('''shell'''):* Performing '''Linux Tutorials''' ('''11 Weekly Tutorials x 2% = 22% of your final grade'''<u>c7host VM Details):</u>* Performing '''Linux Practice Questions''':* Performing '''Review Tutorial''' ('''8 Sections x 1% = 8% of your final grade''')
'''Method 1: Run ssh Command from command prompt:'''
[[Image:gp1.png|thumb|right|130px|The '''Perform Seneca Student VPN''' service must be connected.]]You will now learn a quick and simple method of connecting to your Matrix account by opening<br>a text-based '''terminal''' (in any OS) and issuing the Following Steps:'''ssh command'''.<br><br>
'''Perform the Following Steps:''' #During If you want to connect to your Matrix account from home, you MUST first connect to the Seneca Student VPN.<br>Make certain that your '''Seneca Student VPN is connected'''.<br><br>'''NOTE:''' If you haven't set this up, refer to the installation processfollowing link for instructions;<br>https://students.senecacollege.ca/spaces/186/it-services/wiki/view/1025/student-vpn<br><br>You only have to connect to your Seneca student VPN once during the day, <br>or while you are logged into your computer.<br><br># Determine which '''operating system''' that your computer is using.<br><br># Try connecting to your Matrix account using the instructions in the '''table''' below based on <u>your</u> '''current operating system'''.<br><br><table style="margin-left:50px;"> <tr valign="top" style="text-align:center;"> <th>'''Windows 10 (or above):'''</th> <th>'''macOS:''' </th> <th>'''Linux:''' </th> </tr> <tr> <td>*From the start menu, type '''cmd''' and launch program*In the command terminal, enter the following command:<br><span style="color:blue;font-weight:bold;font-size:.75em;">ssh senecausername@matrix.senecacollege.ca</span> </td> <td>*Click ''Launchpad'' icon, type '''terminal'''<br>and press '''ENTER'''*In the terminal, enter the following command:<br><span style="color:blue;font-weight:bold;font-size:.75em;">ssh senecausername@matrix.senecacollege.ca</span> </td> <td> *From the menu, choose:<br>'''Applications''' > '''System Tools''' > '''Terminal'''*In the terminal, enter the following command:<br><span style="color:blue;font-weight:bold;font-size:.75em;">ssh senecausername@matrix.senecacollege.ca</span> </td> </tr></table><ol><li value="4">When connecting securely for the '''first time''', a '''dialog box''' will required appear to create share a "'''root passwordpublic key''' " with your Matrix account in order to make your interaction between your workstation and the remote Linux server secure within the network (for administration i.e. encrypted to prevent unauthorized accessby other users) <br><br>''<b>FYI:</b> To make communications over a network '''secure''', a computer generates '''two keys''': a '''private key''' that is kept on the computer, and create a '''regular user accountpublic key''', which can be shared with other computers. Click on Transmissions from your computer uses the private key to encrypt ('''Root Passwordscramble''' ) transmission to the remote computer, which in turn, uses the public key to decrypt (unscramble) the transmission. Likewise, the remote computer uses the public key to encrypt (scramble) transmissions and enter your root passwordcomputer uses the private key to decrypt ('''unscramble''') those transmissions. Think of an appropriate password ''<br><br></li><li>Type '''yes''' and record that press '''ENTER''' to share your public key.<br><br>Next, a '''dialog box''' will appear prompting you for your Matrix account '''password somewhere ''' in case you forget! An indicator will appear order to gain entry to show you how secure your Matrix account.<br>Your Matrix password is. Retype <u>identical</u> to your root Seneca password and click .<br><br>'''DoneNOTE:''' (As you type the password, the text may have be '''hidden''' to click Done prevent others from viewing your password<br><ubr>twice</uli><li> if Enter your Seneca password is not considered and press '''ENTER'''<br><br></li>'''NOTE:''' If you encounter an '''error message''', this can occur for several reasons:<ol><li>You mis-spelled the '''name of the server'''</li><li>You mis-spelled your Matrix '''username''' (same username that you connect to ''my.senecacollege.ca'')</li><li>You have '''CAPS LOCK''' on by mistake (your username should be a strong password'''lowercase''' only).#</li><li>You need mis-spelled your '''password''' (same password that you connect to create a regular user account''my.senecacollege. This account will be used ca'')<br><br>If you continue to graphical log into experience the same problems, click on the following link for IT service desk contact info: <br>[https://students.senecacollege.ca/spaces/190/support/wiki/view/1473/contact-its '''IT service desk'''].<br><br></li></ol><li>If you entered your host machinepassword correctly, the '''Matrix Linux shell''' should appear where you can enter Linux commands. It is never recommended <br><br>The '''Matrix''' server has been configured to allow users to graphically log into a graphical '''only interact with the Linux/Unix system as rootOS by issuing commands'''. It <br>The main reason for this is better to log into a regular user account, then run a command '''force students to login as root (you will learn how to do this later in this lab)issue Linux commands'''.#Click <br><br></li><li>To '''User Creationexit''' and enter your Matrix session, type the command <span style="color:blue;font-weight:bold">exit</span> followed by '''ENTER'''full name<br><br>'''NOTE:''' You should notice that you are returned to the original command prompt where you issued the ''ssh'' command.<br><br></li><li>Type the same command at the '''command terminal prompt''': <span style="color:blue;font-weight:bold">exit</span> followed by '''ENTER''', <br><br>'''usernameNOTE:''', You should notice that the you are disconnected and an appropriate that the original terminal window has '''passwordautomatically closed''' (.<br><br></li><li>Try accessing your Matrix account, and confirm password)then exiting your Matrix account several times to become familiar with this process. Click <br><br>You will now learn an '''Donealternative method''' to finish access your Matrix account (click twice if password is not considered to be you have an MS Windows machine)<br>by downloading and running a strong password)graphical SSH application.<br/li></ol><br>{|width="50%" cellspacing="0"
You can also connect to your Matrix server account in the '''Seneca Computer lab via MyApps'''Answer Investigation 1 observations (all parts and questions) in .<br><br>One advantage of this method is that your lab log bookare at the college; therefore, '''you do NOT have to worry about connecting to the Seneca VPN'''.Another advantage of using this method is to introduce you to a '''graphical program''' to allow you connect to your Matrix account as opposed to using the '''ssh''' command (shown in the previous section).<br>
You will now use '''MyApps''' on your Windows workstation in your Seneca lab room to launch an application<br>to allow you to connect and login to your Matrix server account.
[[Image:apps-anywhere.png|thumb|right|250px|Several SSH applications will appear. We will use the application called '''SSH Client''' for this practice tutorial. ]]
You can '''configure''' the SSH application to adjust elements such as the '''window size''' and '''text font type''' and text '''font size'''. We will be showing you how to configure your SSH Secure Shell Client, but the other applications can allow you to configure their settings.<br><br>
'''Perform the Following Steps:'''
:* Learn the basic '''Linux command structure''' (''arguments'' and ''options''):* Learn how to get ''To Disable 'help''' for Linux commands via the Locked Screen-saver, '''online manual''' (i.e. '''man''' command).:* Perform the following steps'''Basic Shell Editing''':* Issue a '''program'''to confirm that you connected to your Matrix account
The Bash shell allows you to interact with Linux by typing commands.
<span style="font-family:'''Perform the following stepscourier;color:'''blue;font-weight:bold">command argument1 argument2 ... </span>
# Make sure Confirm that you're are logged in as rootinto your Matrix account. # Issue the following Linux command: <bspan style="font-family:courier;color:blue;font-weight:bold">pwd<code/span>#* '''Explanation:''' The output from this Linux command shows your '''current location''' on the Matrix server (otherwise known as your '''p'''resent '''w'''orking '''d'''irectory). This represents a '''directory pathname''' to your home directory. We will discuss ''pathnames'' later in this course.# Issue the following Linux command: <span style="font-family:courier;color:#3366CCblue;font-sizeweight:bold">ls</span>#* '''Question:''' What do you notice?#* '''Answer:1''' If there are any files in your home directory, only their file names are displayed.3em# Change your directory location by issuing the following command: <span style="font-family:courier;color:blue;font-weight:bold">su cd /etc</span># Issue the following Linux command to confirm your changed current location: <span style="font-family:courier;color:blue;font-weight:bold">pwd</span>#* '''Result:''' Your Linux session should display <code>/etc/</code>when running this command. If your output is different, retrace your steps to make sure you haven't skipped anything or had a typo in a command.# Issue the following Linux command again: <span style="font-family:courier;color:blue;font-weight:bold">ls</bspan># Edit * '''Question:''' What do you notice? How is this different from the last time you ran it?# Re-run the file ls command using an '''option''': <span style="font-family:courier;color:blue;font-weight:bold">ls -l</etcspan>#* '''Question:''' What do you notice?#* '''Answer:''' The '''-l''' option combined with the '''ls''' command displays a '''detailed''' ("''long''") listing of the same files, providing you with more information about each file. This is called metadata (data about data), and includes information such as last modified date, file size, ownership and permissions.# Return to your home directory: <span style="font-family:courier;color:blue;font-weight:bold">cd</selinuxspan># Now confirm you've changed back to your home directory: <span style="font-family:courier;color:blue;font-weight:bold">pwd</configspan>#* '''Result: ''' The shell should display <bcode>/home/''yourusername''</code># Issue the following Linux command: <span style="font-family:courier;color:#3366CCblue;font-sizeweight:1.3em;bold">vim ls /etcbin</selinux/configspan># Issue the following Linux command to confirm your current location: <span style="font-family:courier;color:blue;font-weight:bold">pwd</span>#* '''Question:''' What do you notice?#* '''Question:''' What makes this command with that argument useful if you are currently located in your home directory?# Issue the following Linux command: </codespan style="font-family:courier;color:blue;font-weight:bold">clear</bspan># In the editing session, set * '''SELINUXQuestion:''' to What do you notice? Why is this command helpful?#* '''Tip:'''The shortcut keys to clear the screen for the Bash shell are: <span style="font-family:courier;color:font-weight:bold">ctrl-l</span># Issue the following Linux command: <uspan style="font-family:courier;color:blue;font-weight:bold">disabledwho</uspan>#* '''Question:''' What information does this command show?#* '''Answer:''' (from This command lists users that are logged into the same Linux server as yourself.#* '''enforcingNOTE:''' Remember that the Matrix Linux cluster contains several servers (or nodes) and save your editing session.It won't display all users logged into the cluster, only the ones on the same node as you. # Issue the following Linux command: <span style="color:blue;font-weight:bold">whoami</span># Restart your VM.* '''Question:''' What does this command display?# You can check * '''Question:''' What do you think is the status purpose of SELinux at any time at this command?# Issue the following Linux command line by typing: <bspan style="font-family:courier;color:blue;font-weight:bold">cal<code/span>#* '''Question:''' What does this command do?# Issue the following Linux command: <span style="font-family:courier;color:#3366CCblue;font-sizeweight:1.3em;bold">sestatuscal 2035</span>#* '''Question:''' How and why is the output different?# Issue the following Linux command: </codespan style="font-family:courier;color:blue;font-weight:bold">cal 2 2035</bspan>#* '''Question:''' What do each of these numbers do?#* '''Question:''' What do you think would happen if you reversed the order of those arguments? (i.e. cal 2035 2)
=== Part 4: Perform Software Updates=== Running software updates regularly is an important part of keeping your computer secure and stable. On Getting Help with Linux, we use package managers to install software and updates. Package managers not only perform installations, but they keep track of everything that is currently installed on the system for easy management. For CentOS, this manager is called yum. Yum is also the command used. :'''Perform the following steps:''' # Open Terminal.# Login as root: <b><code><span style="color:#3366CC;font-size:1.3em;">su -</span></code></b># Type: <b><code><span style="color:#3366CC;font-size:1.3em;">yum update</span></code></b># Follow the prompts.# If there is a kernel update, reboot your system. (There usually is on a first update after OS installation.) '''Answer Investigation 2 observations (all parts and questions) in your lab log book.''' = INVESTIGATION 3: Using Shell Scripting to Generate System Information Reports ={|width="40%" align="right" cellpaddingCommands="10"|- valign="top"|{{Admon/note|Bash Shell Scripting Reference Guide:|<br>'''<u>She-bang Line</u>'''<ul><li>Forces shell script to run in a specific Shell</li><li>Must be at beginning of first line (eg. '''#!/bin/bash''')<br><br></li></ul>'''<u>Variables</u>'''<blockquote>'''Environment'''<ul><li>System-wide or "global" variable</li><li>Usually appear in UPPERCASE letters</li><li>Can view with command: '''set | more'''</li><li>'''$''' in front to expand variable to value<li>Examples: '''USER''', '''PATH''', '''HOME''', '''SHELL'''</li></ul></blockquote><blockquote>'''User-defined''' <ul><li>Variable created by user (command line, scripting)</li><li>Examples:<br>''myVar="my value"; readonly myVar; export myVar''<br>''read -p "enter value: " myVar''</li></ul></blockquote><blockquote>'''Positional parameters'''<ul><li>Assign values with set command or shell script arguments</li><li>These variables are numbered (eg. $1, $2 ... $10}</li><li>Special parameters: $*, $@, $#, $$, $?<br></li></ul></blockquote>'''<u>Command Substitution</u>'''<ul><li>Useful method to expand output from a command to be used as an argument for another command.</li><li>Examples:<br>''file $(ls)''<br>''set $(ls);echo $#;echo $*''<br>''echo "hostname: $(hostname)"''<br><br></li></ul>'''<u>if / elif / else statements</u>'''<ul><li>If a command runs (even pipeline command like to grep to match) will be true (0); otherwise, false (non-zero), thus can use with logic statements.</li>Example:<br>''if echo $myVar | grep "match"''<br>''then''<br>''echo "Match"''<br>''fi''<br></li><li>The '''test''' command is used to test conditions. Square brackets '''[ ]''' is short-cut for test command (args contained inside with spaces). The '''exit''' command can be used to terminate the shell script with a false value.<br>Example:<br>''if [ $USER = "root" ]''<br>''then''<br> ''echo "You must be root" ''<br> ''exit1''<br>''fi''<br></li><li>For numberic comparison, use the '''test options''': '''-gt''','''-ge''', '''-lt''', '''-le''', '''-eq''', '''-ne'''<br>Example:<br>''if [ $grade -gt 79 ]''<br>''then''<br> ''echo "You get Good Mark"''<br>''elif [ $grade -gt 49 ]''<br>''then''<br> ''echo "You pass"''<br>''else''<br> ''echo "You fail"''<br>''fi''<br></li><li>For testing for file information, you can use '''-d''' to test if directory pathname exists, and '''-f''' if the file pathname exists. You can use '''!''' for negation.<br>Examples:<br>''if [ -d directory-pathname ]''<br>''then''<br> ''echo "directory exists"''<br>''fi''<br><br>''if [ ! - f file-pathname ]''<br>''then''<br> ''echo "File does not exist"''<br>''fi''</li></ul>}}|}
With the Linux OS containing over '''2500''' commands and utilities, it's important for Linux users and Linux system administrators (sysadmin) to learn how to use commands “on-the-fly”.
You will now learn how to perform '''command line editing''' to correct syntax errors while typing Linux commands PRIOR to pressing the ENTER key.
==Command Line Editing==[[Image:command-line-editing.png|thumb|right|520px|Command Line Editing Shortcut Keys. ]]Learning '''Perform the Following Stepsshortcut keys''' in any OS terminal will allow you to be more productive as a ''Linux user'' or ''Linux System Administrator'' (commonly referred to as:'''Linux sysadmin''').
'''Perform the Following Steps:'''
[[Image:meta-key.png|thumb|right|370px|To make '''alt-f''' key work, select '''Edit''' -> '''Settings''' -> '''Keyboard''', and select the checkbox '''Use ALT as Meta key (and Escape)'''.]]
# Type the following Linux command, but DON’T press the ''ENTER'' key:<br><span style="font-family:courier;color:blue;font-weight:bold">cd /bin</span><br><br>
# Press the <span style="font-family:courier;color:blue;font-weight:bold">ctrl-a</span> key combination. What happens?<br><br>'''NOTE:''' To make '''alt-f''' key work when use the '''GRAPHICAL Windows SSH Client application''', select '''Edit''' -> '''Settings''' -> '''Keyboard''', and select the checkbox '''Use ALT as Meta key (and Escape)'''.<br><br>
# Press the <span style="font-family:courier;color:blue;font-weight:bold">alt-f</span> key combination '''two times'''<br>(OPTION+right-arrow for Mac OSx).<br><br>
# Press the <span style="font-family:courier;color:blue;font-weight:bold">alt-b</span> key combination '''one time'''.<br>(OPTION+left-arrow for Mac OSx).<br><br><table align="right"><tr valign="top"><td>[[Image:ctrl-b.png|thumb|right|150px|'''alt-b''' moves one word backwards for Windows OS]]</td><td>[[Image:ctrl-w.png|thumb|right|150px|'''ctrl-w''' deletes a word to <u>left</u> of the cursor.]]</td><td>[[Image:new-ls.png|thumb|right|150px|After command is deleted, then type new command and press '''ctrl-e''' to move to end of the command line.]]</td></tr></table>
# Press the <span style="font-family:courier;color:blue;font-weight:bold">ctrl-w</span> shortcut key. What happens?<br><br>
# Type the following command: <span style="font-family:courier;color:blue;font-weight:bold">ls</span><br><br>
# Press the <span style="font-family:courier;color:blue;font-weight:bold">ctrl-e</span> key combination<br><br>What happens?<br><br>
# Press the <span style="font-family:courier;color:blue;font-weight:bold">ENTER</span> key to execute the command.<br><br>
# Press the <span style="font-family:courier;color:blue;font-weight:bold">up arrow</span> key. What happens?<br><br>
# Press the <span style="font-family:courier;color:blue;font-weight:bold">ctrl-u</span> key combination. What happens?<br><br>
# Press the <span style="font-family:courier;color:blue;font-weight:bold">up arrow</span> key combination, and see what happens when you press <span style="font-family:courier;color:blue;font-weight:bold">BACKSPACE</span> , <span style="font-family:courier;color:blue;font-weight:bold"><ctrl><BACKSPACE></span> and <span style="font-family:courier;color:blue;font-weight:bold"><ctrl><h></span>.<br>Why is it important to know those series of key combinations?<br><br>
# Press the <span style="font-family:courier;color:blue;font-weight:bold">ctrl-u</span> key combination to clear the line.<br><br>
# Press the <span style="font-family:courier;color:blue;font-weight:bold">ctrl-l</span> key combination. What happens? What is the advantage of using '''ctrl-u''' as opposed to '''ctrl-l'''?<br><br>The Bash shortcut keys that you just learned are sufficient to perform Bash Shell editing.<br>Although you are NOT required to learn other short-cut keys, here is a link to a listing in case you are interested:<br>[https:// ostechnix.com/list-useful-bash-keyboard-shortcuts/ Useful Bash Shell Keyboard Shortcuts]
These programs (known as Shell Scripts) will check your work and offer feedback if you made mistakes, so you can make corrections. Making corrections (i.e. troubleshooting) and re-running these checking programs until you are successful will help students gain "hands-on" experience as well as "trouble-shooting experience.
'''Perform the Following Steps:'''
NOTE: ONLINE ASSIGNMENTS ARE RETIRED AND REPLACED WITH ONLINE TUTORIALS and REVIEW QUESTIONS
===Part 2:'''NOTE:''' Although it is possible to copy and paste, is it highly recommended to manually enter the following Bash Shell scripting content to become familiar with writing Bash Shell scripting code. Remember: you will be required to create a Bash Shell script on your final exam, so you need the practice!Performing Online Assignments ===
You are required to perform '''3 online assignments''' throughout this course. This online assignment is used to teach and reinforce<br>Linux commands to gain experience for '''quizzes''', '''test 1''' (midterm) and '''test 2''' (final).
<br>
= LINUX PRACTICE QUESTIONS =
:'''Perform the Following Stepshttps:'''//wiki.cdot.senecacollege.ca/uli101/files/uli101_week1_practice.docx
Author: Murray Saul
License: LGPL version 3
Link: https://www.gnu.org/licenses/lgpl.html
_________________________________________________________________________________
[[Category:OPS235]][[Category:OPS235 Labs]][[Category:CentOS 7]][[Category:SSD2ULI101]]