Open main menu

CDOT Wiki β

Changes

OPS235 Lab 1 - CentOS7

4,601 bytes added, 13:10, 1 April 2015
no edit summary
|
# Disabling SELinux is quite simpleYou may have learned about creating and running Bash Shell Scripts in your ULI101 course. Shell scripts help Linux users and system administrators to automatic repetitive tasks to become more efficient and to help them save time. You will be reviewing and building a basic Bash Shell script to generate your newly-installed Linux host machine. Take time to view Shell Scripting Tips on the right-hand side, just edit and run the file '''online tutorial to learn how to create simple shell scripts. # Make certain to log out of your root account and remain as a regular user.# Open a Shell terminal and use a text editor (such as <b><code><span style="color:#3366CC;font-size:1.2em;">vi</span></code></b> or <b><code><span style="color:#3366CC;font-size:1.2em;">nano</etcspan></selinuxcode></config''' and set SELINUX b>) to disabledcreate a Bash Shell script called: <b><code><span style="color:#3366CC;font-size:1.2em;">report.bash</span></code></b> in your current directory.# Add additional Enter the following text regarding disabling SELinuxcontent into your text-editing session: <br><brpre style="font-family:courier;font-weight:bold;padding-left:4px;margin-left:15px;">#The CentOS !/bin/bash # Forces script to run in the bash shell # Author: *** INSERT YOUR NAME ***# Date: *** CURRENT DATE ***## Purpose: To present sysadmin to create an software inventory# report containing selected elements## USAGE: ./report.bash  if [ $USER != "root" ] # checks to see if user is root, and exits script if notthen echo "You must be logged in as root to run the command." >&2 # >&2 is updated frequently a "redirection trick" to add features, fix bugsconvert output as stderr echo "Either login as root or issue command \"sudo ./report1.bash\"" >&2 exit 1fi</pre> <ol><li value="4">Save your editing session, assign your report.bash file read and execute permissions (at least for the owner) and run by typing: <b><code><span style="color:#3366CC;font-size:1.2em;">./report.bash</span></code></b></li><li>Did it run? If not what do you think you need to do in order to run the Bash Shell Script?</li><li>Issue the command <b><code><span style="color:#3366CC;font-size:1.2em;">su</span></code></b> and upgrade securityrun the Bash shell again. Did it work?</li><li>Reopen your text-editing session for report. Perform a system update bash and add the following lines of code to get the latest versions bottom of the packages installedshell script file:</ol> <pre style="font-family:courier;font-weight:bold;padding-left:4px;margin-left:15px;"># Create report title echo "SOFTWARE ASSET REPORT FOR INSTALLED LINUX SYSTEM" > /root/report.txtecho "Date: Start the Firefox web browser, turn off popup window blocking $(select '''Edit''date +'%A %B %d, %Y (%H:%M:%p)'''Preferences''')" >> /root/report.txtecho >> /root/report.txt </pre> <ol><li value="8">Save and run the bash shell script. View the contents of the file called "report.txt" that was generated. Notice how the redirection symbol &gt; is used at the beginning of the report, and then select the '''Content''' tab other redirection symbol &gt;&gt; is used to help "grow" the report with the other content.</li><li>The only remaining content of the report would be the system information. We can use a shell scripting trick called "command substitution" $( .. ) in order place results from an command to be used by another command (like echo). Re-edit the shell script and uncheck add the box to '''Block Popups'''following code at the bottom of the shell script file:</li></ol> <pre style="font-family:courier;font-weight:bold;padding-left:4px;margin-left:15px;">echo >> /root/report.txtecho "Hostname: $(hostname)" >> /root/report.txtecho >> /root/report.txtecho >> /root/report.txtecho "Kernel Version: $(uname -rv)" >> /root/report.txtecho >> /root/report.txt</pre> <ol><li value="10">Save, then return run the script, and view the resulting file contents.</li><li>Edit the shell script and issue the build the report to your web-browserinclude empty lines, load a pagetitles, and when prompted, login to SeneNETcontent for the remaining commands: <b><code><span style="color:#3366CC;font-size:1. #Open a terminal 2em;">ps aux</span></code></b> and type <b><code><span style="color:#3366CC;font-size:1.2em;">suifconfig</span></code></b> to start a .</li><li>Save, run and confirm that the shell script is working correctly.</li><li>What would be the use of keeping this shell script as roota Linux system administrator?</li></ol> <ol><li value="14">Here are some more "complex" Bash Shell scripts, that perform the same task. Although you are not require to understand some of these other tricks, it is recommended that you view the contents of the scripts and save them for future consideration or exmaples.</li><li>The <b><code>wget</code></b> command can be used to quickly download files from the Internet. Enter Issue the following command :<blockquote><b><code><span style=" pointer-events:none;cursor:default;color:#3366CC;font-size:1.2em;">yum updatewget https://scs.senecac.on.ca/~murray.saul/text-report.bash</span></code></b> This will download and install all of the packages </blockquote></li><li>Verify that have been updated since the installation DVD image file '''text-report.bash''' was createddownloaded to your current directory.</li><li>Assign read and execute permissions for this file by issuing the command: <b><code>chmod u+rx text-report. If you complete bash</code></b></li><li>Run this Bash Shell script by issuing the command at Seneca : <b><code>./text-report.bash</code></b></li><li>Check to see if it should run quite fast as Seneca College hosts created a CentOS Repository mirror (a copy report in your current directory. What is the purpose of all the report?</li><li>Use the <b>vi</b> text editor to view the contents of the current CentOS packagesfile <b>text-report.bash</b>. Can you understand how this script works?<br><br></li><li>Use the <b><code>wget</code></b> command to download, study, and run the following shell scripts on a local web server)-line:<blockquote><b><code><span style=" pointer-events:none;cursor:default;color:#3366CC;font-size:1.2em;">https://scs.senecac.on.ca/~murray.saul/report.bash<br>https://scs.senecac.on.ca/~murray.saul/report3.bash</span></code></b></blockquote></li><li>Try to understand what these Bash Shell scripts do.</li><li>You have completed lab1. Proceed to Completing The Lab, and follow the instructions for "lab sign-off".</li></ol>
|width="40%" |{{Admon/tip|SELinux|SELinux stands for '''Security-Enhanced Linux'''. It is a component that helps to better secure the system to protect against intrusion (hackers). SELinux is enabled upon the default install of CentOS. SELinux can be a good thing, if you take care of it and know how it works. For this course it is strongly recommended that you '''disable SELinux by default''' because we won't have the time to reconfigure it every time the labs make it necessary.}}
13,420
edits