Franske ITC-2480 Lab 2

From ITCwiki
Revision as of 19:33, 22 January 2014 by BenFranske (talk | contribs)
Jump to navigation Jump to search

Introduction

In this lab you will install the "links" web browser, download a compressed file, create a directory, copy and move files, extract a .tar.tz "tarball" file, remove files and directories, and install the Apache webserver.

These same instructions apply if you are completing this lab using the VirtualBox virtual machine software or if you are connected to a machine running remotely on the VMware platform. If you are completing this on campus remember to switch your network connection to the SafeConnect-free ITCnet.

  1. Open an SSH console to your Linux system using the PuTTY software, login with your standard user account
  2. Install the links web browser package
    1. Enter root (administrative) mode using the "su" command and your root password
    2. Update your package lists using the "apt-get update" command
    3. Install the aptitude package management utility if it's not already installed using the "apt-get install aptitude" command
    4. Update your aptitude sources using the "aptitude update" command
    5. Search for a description of the "links" package using the aptitude command "aptitude search links"
    6. Install the "links" web browser package using the aptitude command "aptitude install links"
    7. Run the links program using the "links" command and try browsing to a website such as www.google.com or www.debian.org
    8. Quit the links program
    9. Use the "exit" command to leave root user mode and return to your standard login
  3. Practice basic file management and directory navigation commands
    1. Use the links web browser to download the complete works of Shakespeare in .tar.gz format from [1]
    2. Exit the links browser and verify the file has downloaded into your current directory with the "ls -al" command
    3. Create a new directory called "sample-files" using the "mkdir sample-files" command
    4. Copy the Shakespeare.tar.gz file from the current directory into the sample-files directory using "cp Shakespeare.tar.gz sample-files/" note the / on the end of the command which indicates we want to place the file into a subdirectory and not make a new copy of the file in the same directory but with a different name. Pay attention to case, Linux is a case sensitive operating system. You can actually have two different files in the same directory, one called Shakespeare.tar.gz and one called shakespeare.tar.gz
    5. Change your current directory to the sample-files directory using the "cd sample-files" command and verify your directory change using the "pwd" print working directory command
    6. Verify the file has been copied by using the "ls -al" command in the sample-files directory
    7. Delete (remove) the file from the current directory by using the "rm shakespeare.tar.gz" command
    8. Change your directory back to your user's home directory (one level above the subdirectory you're currently in. There are many ways to do this but a common shortcut to move one directory up in the tree is to use the ".." shortcut which means one directory above the current directory so "cd .." will change your working directory up one level.
    9. This time we want to move the shakespeare.tar.gz file into the sample-files directory instead of copying it. Use the "mv shakespeare.tar.gz sample-files/" command to do this.
    10. Verify the shakespeare.tar.gz file is no longer in your current directory then change your working directory to sample-files again and verify that the file has been moved there.
    11. The .tar.gz file is called a "tarball" and is a common way to distribute files on *NIX based systems. These files really have two parts. The first is a TAR file which is a way to pack multiple files and directories into a single file for archival an distribution purposes but does not compress the file in any way, the size will be essentially the same as if you added together all of the files it contains. After the files are put into a TAR file they can be compressed with the gzip program so we add the .gz extension to the filename to indicate this TAR file has been compressed. Other compression programs such as bzip2 can also be used, in that case it would be a .tar.bz2 file. Because TAR files are so frequently gzipped to compress them the command to compress or uncompress a file as been added to the TAR program itself so we don't need to go through two steps. In this case we can uncompress and extract the files using the "tar -zxf shakespeare.tar.gz" command or to see the list of files as they are extracted we can add the -v argument to the command to make the output verbose "tar -zxvf shakespeare.tar.gz"
    12. After running the command to extract and uncompress the file verify it by listing the directory contents. You should see a new subdirectory, it's common and good practice to always include the files in a TAR in their own subdirectory so that when they are extracted they don't clutter the current working directory. Enter the new subdirectory and list the contents to verify the extraction, you should see several files.
    13. Try removing one of the files that was extracted. You might encounter an error if the filename includes a space. Although spaces are allowed in filenames on Linux, it's not recommended because you will need to either quote or escape filenames in some way in order to work with the files. For example if you wanted to remove a file called "a file with spaces.txt" you would either need to enter the command as "rm "a file with spaces.txt"" (including the inner set of quotes) or as "rm a\ file\ with\ spaces.txt" where the backslash character is used to escape the special characters in the filename (in this case spaces, but other characters, like exclamation points, are special as well). Make sure you can remove a file with spaces in the name.
    14. Move up one directory (back to the sample-files directory). Let's say we want to remove the entire Shakespeare directory now. Try using the rm command to do that. The rm command will give you an error because it is designed for removing files, not directories. To remove directories you can use the rmdir command such as "rmdir Shakespeare" but this will also give you an error! The rmdir command requires that a directory be empty before it can be removed. You now have a choice, you could go back into the directory and clear it out, one file at a time using the rm command. Or you could speed things up by removing all the files in it at once using the "rm *" command, which includes a special character, called a wildcard, which stands for all files in the directory. This would work but it still requires a second step and if there were even more levels of directories inside the one you wanted to remove you would have to go through all of them as well. Luckily, Linux has a powerful (but obviously dangerous) command the "recursive remove" command which removes a directory as well as all of the files and subdirectories it contains. You must be careful with this command because, used incorrectly, you could obviously delete everything on your hard drive with a single command. We want to remove the Shakespeare directory and everything it contains so we can use the "rm -r Shakespeare" command. Do this and then verify the directory has been removed.
    15. Navigate back to your user's home directory before continuing.
  4. Install the apache2 package and it's dependencies
    1. On your HOST system open a web browser and try browsing to the IP address of your Linux system. You should get some kind of server unreachable error because there is currently no webserver running on your system.
    2. Use the su command to become the root user in an SSH session to your Linux machine so that you'll be able to install software.
    3. Use the aptitude command to install the "apache2" package, one of the most popular webserver programs on the Internet. You'll notice this time, because it's a more complex program than links, you will be prompted to install several other packages that apache relies on to run, we call these packages "dependencies". One key advantage of using a "package manager" like apt-get or aptitude is that they automatically keep track of dependencies and install packages needed to make the one you're trying to install function properly.
    4. Once the installation process for apache2 is complete you should be able to go back to your host system and try visiting the IP address of your Linux system again or reloading the page. Youl should now see a basic welcome page which indicates you have a webserver up and running on your Linux system. Obviously we haven't done anything exciting with the page yet or setup much security but it really is that simple to turn a Linux system into a basic webserver.
    5. When you are done make sure to use the appropriate command to shutdown your system safely.


New Commands

  • apt-get
  • aptitude
  • cd
  • cp
  • mv
  • rm
  • rmdir
  • tar

Concepts

  • Recursion
  • Packages
  • Dependencies