Changes

Jump to: navigation, search

OPS235 Lab 7 - Fedora17

355 bytes added, 19:54, 3 January 2014
no edit summary
[[Category:OPS235]]{{Admon/caution|DraftLab|This lab has NOT been released for regular distribution. When the lab is ready to be released, this caution banner will disappear.}}
= Setup and Configure Secure Shell Services (ssh) Using Virtual Machines =
[[Category:OPS235]][[Category:OPS235 Labs]]
==Overview==
==Required Materials (Bring to All Labs)==
* '''Fedora 16 17 LIVE CD''' - You can burn this onto a CD-R in the Open Lab* '''Fedora 16 x_64 17 x86_64 Installation DVD''' - You can burn this onto a DVD-R in the Open Lab (or burn image onto a DVD+R if you are using the Freedom Toaster).* '''SATA Hard Disk''' (in removable disk tray)* '''USB Memory Stick''' (minimum 64M)* '''Lab Logbook (Lab5 Reference Sheet)''' (to make notes and observations). 
==Prerequisites==
Each Link below displays online manpages for each command (via [http://linuxmanpages.com/ http://linuxmanpages.com]):
{|width="100%" cellpadding="5" width="50%"|'''Networking Utilities '''|'''Additional Utilities:'''|'''Configuration Files:'''
|- valign="top"
|
*[http://linuxmanpages.com/man1/ssh.1.php ssh]
*[http://linuxmanpages.com/man1/ssh-keygen.1.php ssh-keygen]
*[http://linux.about.com/library/cmd/blcmdl5_ssh_config.htm ssh_config]
*[http://linux.about.com/od/commands/l/blcmdl5_sshdcon.htm sshd_config]
*[http://linuxmanpages.com/man1/scp.1.php scp]
*[http://linuxmanpages.com/man1/sftp.1.php sftp]
*[http://linuxmanpages.com/man8/ping.8.php ping]
*[http://linuxmanpages.com/man8/arp.8.php arp]
*[http://linux.die.net/man/1/ssh-copy-id ssh-copy-id]|*[http://www.linuxcertif.com/man/1/systemctl/ systemctl]*[http://linuxmanpages.com/man1/hostname.1.php hostname]*[http://linuxmanpages.com/man8/restorecon.8.php restorecon]|*[http://linux.about.com/library/cmd/blcmdl5_ssh_config.htm ssh_config]*[http://linux.about.com/od/commands/l/blcmdl5_sshdcon.htm sshd_config]
|}
== Configuring & Establishing an SSH Connection == === Lab Preparation ===
{{Admon/important | Update your systems | It is advisable to perform a <code>yum update</code> on your Fedora host and all 3 VM's.}}
{{Admon/important | Backup your VMs before proceeding | If you did not do it at the end of Lab 6, stop all of your VMs and backup your VM disk images.}}
== Lab Investigations ==
=== Investigation 1: How do you enable the sshd service. ===
{{Admon/note | Use your f16host f17host computer system | Complete the following steps on your fedora host.}}
# OpenSSH should have been installed by default. Lets confirm this by issuing the command:<br /> <code>rpm -qa | grep ssh</code>
# You should see a number of packages installed including <code>openssh-clients</code> and <code>openssh-server</code>
# <code>openssh-server</code> installs a service called <code>sshd</code>, <span style="background-color:yellow">confirm this service is running by issuing the command:</span><br /><code><span style="background-color:yellow">systemctl status sshd.service</span></code># Now check that the <span style="background-color:yellow">sshd service is configured to start for runlevels 2, 3, 4, & 5, by issuing the commandautomatically:</span><br /><code><span style="background-color:yellow">systemctl listis-units enabled sshd</span></code> # <span style="background-color:yellow">If the .service is not configured correctly fix it by issuing the command:</span><br /> <code><span style="background-color:yellow">chkconfig --level 2345 sshd on</span></code>
# Now that you know the service is running investigate what port number and protocol sshd uses by issuing the command:<br /><code>netstat -atunp</code>
# What protocol and port is the sshd process using?
'''Answer the Investigation 1 observations / questions in your lab log book.'''
 
=== Investigation 2: How do you establish an ssh connection. ===
{{Admon/note | | '''Public Key authentication''' is a method of establishing identity using a pair of encryption keys that are designed to work together. One key is known as your private key (which as the name suggests should remain private and protected) and the other is known as the public key. (which as the name suggests can be freely distributed) The keys are designed to work together to encrypt data asymmetrically, that is to say that when we encrypt data with one of the keys it can only be decrypted with the other key from the pair. This means that when we connect, ssh can use the private key that only exists on my system in my account, to encrypt a message. That message can be decrypted by anybody with the corresponding public key. While it doesn't mean the message is secure as anybody could decrypt it with the public key, it does establish my identity, if the host can successfully decrypt the message then it must have come from the one person in possession of the private key. This basic method of authentication is used extensively in many network communications protocols that require the ability to authenticate identity.}}
# Start by generating a keypair as your learn account on fedora2 using the command:<br /><code>ssh-keygen -t dsa</code>
# That should generate output similar to the following:
<pre>
Generating public/private dsa rsa key pair.Enter file in which to save the key (/home/user1/.ssh/id_dsaid_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/user1/.ssh/id_dsaid_rsa.Your public key has been saved in /home/user1/.ssh/id_dsaid_rsa.pub.
The key fingerprint is:
93:58:20:56:72:d7:bd:14:86:9f:42:aa:82:3d:f8:e5 user1@fedora2
</pre>
<ol><li value="3"> After generating the keys it prompts you for the location to save the keys. The default is <code>~/.ssh</code> Your private key will be saved as <code>id_dsaid_rsa</code> and your public key will be saved as <code>id_dsaid_rsa.pub</code></li></ol>
{{Admon/tip | Lengthy Passphrases | You will then be prompted for a passphrase. The passphrase must be entered in order to use your private key. Passphrases are more secure than passwords and should be lengthy, hard to guess and easy to remember. For example one passphrase that meets this criteria might be "seneca students like fish at 4:00am". Avoid famous phrases such as "to be or not to be" as they are easy to guess. It is possible to leave the passphrase blank but this is dangerous. It means that if a hacker were able to get into your account they could then use your private key to access other systems you use.}}
<ol><li value="4"> Once your keys have been saved you should check to make sure the permissions of the <code>.ssh</code> directory and your key files are secure. </li>
<li> Use the following commands to secure them:<br /><code>chmod 700 ~/.ssh</code><br /><code>chmod 600 ~/.ssh/id_dsaid_rsa*</code><br /></li>
<li>The next step is to copy your public key to fedora3 (the remote host). You can use the scp command to do it.</li>
<li><code>scp</code> (secure copy) is used to copy files between hosts over the ssh protocol. The files are sent over an encrypted channel as is all ssh traffic. </li>
<li>Issue the command:<br /><code>scp ~/.ssh/id_dsaid_rsa.pub ops235@fedora3:</code></li>
<li>This will copy your public key to your ops235 home directory on fedora3.</li>
<li>The ''':''' is important as it separates the hostname from the path where it is copied to. </li>
<li>Now ssh to fedora3 using a password to authenticate.</li>
<li>Once logged in to fedora3 we need to add the public key to your list of authorized_keys</li>
<li>he safest way to do this is to append the contents of <code>id_dsaid_rsa.pub</code> to the <code>.ssh/authorized_keys</code> file. To do this use the command:<br /><code>cat ~/id_dsaid_rsa.pub >> ~/.ssh/authorized_keys</code></li></ol>
{{Admon/important | Note! | You don't want to overwrite the file as it may contain multiple public keys. Make sure you are using the append redirection '''>>''' and not '''>'''.}}
<ol><li value="16"> Once again you should secure the <code>.ssh</code> directory and the <code>authorized_keys</code> file using the following commands:<br /><code>chmod 700 ~/.ssh</code><br /><code>chmod 600 ~/.ssh/authorized_keys</code></li>
-->
<ol><li value="3">xNow issue the command <code>ssh-copy-id -i ~/.ssh/id_rsa.pub fedora3</code></li> <li value="19">Now we can ssh into fedora3 from fedora2 using 2 different authentication methods.</li><li>MaKe Make certain to logout of your Fedora3 system. Use the <code>hostname</code> command to verify you are back in your Fedora2 server.</li><li/ol'''Answer the Investigation 3 question observations / questions in your lab log book.</li></ol>''' == Using SSH &amp; Other Secure Shell Utilities ==
=== Investigation 4: How do you use scp and sftp. ===
{{Admon/note | Note! Use your fedora2 VM | Complete this investigation on your fedora2 VM.}}
{{Admon/note | | There are 2 common command line tools for transferring files between hosts over an encrypted ssh connection, <code>scp</code> and <code>sftp</code>. <br /> <code>sftp</code> is an interactive file transfer program that functions much like an ftp client. }}
# To connect to a remote host type the command:<br /><code>sftp ops235@fedora3</code>
# Experiment with <code>scp</code> to copy a file from fedora3 directly to fedora1.
{{Admon/tip| SELinux | SELinux may prevent ssh from accessing your home directories on Fedora 1 because you created a new filesystem there. You can reset the security context of the /home directory with this command: <code>restorecon -Rv /home</code>}}
<ol><li value="9">'''Answer the Investigation 4 question observations / questions in your lab log book.</li>'''</ol>
=== Investigation 5: How do you use ssh to tunnel X. ===
{{Admon/note | Note! Use your fedora2 and fedora1 VMs | Complete this investigation on your fedora2 and fedora1 VM's.}}
{{Admon/tip | fedora1 VM iptables and ssh service | You may need to adjust the firewall on your fedora1 host to complete this section, and verify that the sshd service is running on that VM.}}
# Where was the file saved?
# Experiment with running other GUI applications through <code>ssh</code>.
#  '''Answer the Investigation 5 question observations / questions in your lab log book.'''  == Further Securing your Secure Shell Connection ==
=== Investigation 6: How do you use ssh to tunnel other traffic. ===
{{Admon/note | Note! Use your fedora2 and fedora1 VMs | Complete this investigation on your fedora2 and fedora1 VM's.}}
{{Admon/note | | You can also use an ssh connection to tunnel other types of traffic. There could be different reasons for doing this. For example tunneling traffic for an unencrypted application/protocol through ssh can increase the security of that application. Alternatively you could use it to circumvent a firewall that is blocking traffic you wish to use but allows ssh traffic to pass through.}}
# In this investigation fedora1 will be your http server and fedora2 will be your client.
# On the HTTP server (fedora1), make sure the Apache web server is installed by typing the command:<br /><code>rpm -q httpd</code>
# If it is installed check the configuration of the service to see if it is automatically started at any runlevels by issuing the command:<br /><code>chkconfig --list systemctl status httpd.service</code># If it has not been started automatically start the service using the command:<br /><code>systemctl start httpd.service httpd start</code>
# Confirm that httpd is listening to TCP/80 using the command:<br /><code>netstat -atnp</code>
# Create a small html document called <code>/var/www/html/index.html</code> that displays a short message.*
<li>You should see the index.html page on fedora1.</li>
<li>Close the ssh connection and verify that the port 20808 is no longer listening.</li>
<li>nswer the Investigation 6 question in your lab log book.</li></ol>
'''Answer the Investigation 6 observations / questions in your lab log book.''' === Investigation 7: How do you make sshd more secure. ===
{{Admon/note | Note! | Complete this investigation on your fedora2 and fedora1 VM's.}}
# Before we can use this new port we must change our firewall to allow traffic through the new port number and block access to port 22:<br /><code>iptables -I INPUT -p tcp -s0/0 --dport 22 -j DROP</code><br /><code>iptables -I INPUT -p tcp -s0/0 --dport 2200 -j ACCEPT</code>
# To test the new port connect to fedora1 from fedora2 using the following command:<br /><code>ssh -p 2200 user@fedora1</code>
{{Admon/important|Cannot connect via SSH?|To fix issues with the ability to ssh, on both machines:<ul><li>Ensure ssh is running. Systemctl status sshd.service.</li><li>Disable selinux by going into /etc/selinux/config and change "enforcing" to "disabled"; "targeted" to "minimum".</li><li>If your are still encountering problems flush iptables.</li></ul>}}
{{Admon/tip | Tip! | For scp access the option to be used is: <code>scp -P 2200</code>}}
{{Admon/tip | Tip! | For more ideas on making sshd more secure consult the HOW-TO link above.}}
<li>Attempt to connect to all of your VM's as root and other users using both public key and password authentication. Use some su and sudo commands also. </li>
<li>Inspect the log to see what kind of information is logged.</li>
<li/ol'''Answer the Investigation 7 question observations / questions in your lab log book.</li></ol>''' 
== Completing the lab ==
# have secured ssh against root access
== Preparing for the Quizzes ==
# What port does sshd use by defaults?
13,420
edits

Navigation menu