Lab 2 mnjk
Revision as of 17:46, 30 January 2021 by NateHaleen (talk | contribs) (→Install the Apache 2 Webserver)
Introduction
In this lab you will perform the following tasks:
- Installing the links web browser
- Downloading a compressed file
- Creating a directory
- Copying and moving files
- Extracting a .tar.tz "tarball" file
- Removing files and directories
- Installing the Apache webserver
- Installing Python and its dependencies
This lab assumes that you know the IP address of your Linux system and are connected to the ITCnet VPN network. If you need help with these steps please see a previous lab.
You will use the following commands:
Preliminaries
- Ensure your VM is powered on in Netlab
- Note: you should have shut it down at the end of the last lab
- Note: you will need to make a reservation in Netlab to power on your VM.
- Make sure you have the current IP address of your Linux system
- If your Linux VM has been powered off for some time since you checked the IP address in a previous lab you may have received a new IP address, so be sure to check your IP address again and use that IP address in this lab.
- Open an SSH console to your Linux system using the PuTTY software
- Log in with your standard user account
- From this point on we will be working only through an SSH connection to the server so unless you have a problem with network access to your VM, or you need to power it on again you should not need to make Netlab reservations or use the Netlab interface for quite some time.
Install the links web browser package
Video Tutorial: Installing the Links Web Browser
- Update your package lists using the following command:
sudo apt update
- Search for a description of the links package using the following apt command to search for packages with links in the package name.
apt search --names-only links
- Check the details of the links software package using the following command:
apt show links
- Install the links web browser package using the following aptitude command:
sudo apt install links
- Run the links program using the following command:
links
- Try browsing to a website such as www.google.com or www.debian.org.
- Press the letter "q" on your keyboard to quit links.
- Because software installation and updates need to be done as an administrator we need to put sudo in front of these commands. You will likely need to enter your password again unless you've recently used sudo for something else and your session has not timed out yet.
- TIP: You could further restrict your search using regular expressions instead of just searching for "links" such as apt search --names-only ^links which will only search for packages that start with the word links. You can learn more about regular expressions at RegexOne and Regular-Expressions.info among many other places. These are frequently used in system administration and programming so it's worth your while to get at least a basic understanding of them.
- TIP: You can also expand your search to include searching the full package descriptions instead of just the names like apt search links which returns many more results.
- Hint: Press CTRL-G lets you enter a URL.
- Hint: Press ALT-F to get a menu bar to appear on your screen which you can then go through using arrow keys.
There are many other text-based browsers to choose from. Some of these are more recent and have advanced features like handling SSL and cookies better. If you are interested check out w3m or lynx
Video Tutorial: Basic File Management and Navigation
- Use the links web browser to open the page http://www.franske.com/shakespeare.tar.gz
- Download the shakespeare.tar.gz file from that page.
- Exit the links browser and verify the file has downloaded into your current directory with the following command:
ls -al
- Create a new directory called sample-files using the following command:
mkdir sample-files
- Copy the shakespeare.tar.gz file from the current directory into the sample-files directory using:
cp shakespeare.tar.gz sample-files/
- Change your current directory to the sample-files directory using:
cd sample-files
- verify your directory change using the print working directory command:
pwd
- Verify the file has been copied by using the following command inside the sample-files directory:
ls -al
- Delete (remove) the file from the current directory by using:
rm shakespeare.tar.gz
- Change your directory back to your user's home directory (one level above the subdirectory you're currently in.
- Use the following command to do this:
mv shakespeare.tar.gz sample-files/
- 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.
- Run the command to extract and uncompress the file.
- Verify it by listing the directory contents.
- Enter the new subdirectory and list the contents to verify the extraction, you should see several files.
- Try removing one of the files that was extracted.
- Move up one directory (back to the sample-files directory).
- Try using the following command to do that:
rm
- Try it!
rmdir Shakespeare
- Do this and then verify the directory has been removed.
- Navigate back to your user's home directory before continuing.
- This command lists the files in the current directory.
- 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
- 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.
- This time we want to move the shakespeare.tar.gz file into the sample-files directory instead of copying it.
- Again, note the / on the end of sample-files/ indicating we want to put it in a directory named sample-files instead of renaming shakespeare.tar.gz to a file called sample-files.
- The .tar.gz type files are sometimes called a "tarball" and they are a common way to distribute files on *NIX (UNIX/Linux/BSD/POSIX) 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
- 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.
- 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" (with the 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.
- Let's say we want to remove the entire Shakespeare directory now.
- 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.
Install the Apache 2 Webserver
Video Tutorial: Installing Apache 2
- On your HOST system open a web browser and try browsing to the IP address of your Linux system.
- Use the apt show command to review details of the apache2 package
- After reading through the information go ahead and install the apache2 package using apt install.
- Once the installation process for Apache 2 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.
- You should get some kind of server unreachable error because there is currently no webserver running on your system.
- Apache is 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, 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.
- You 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.
Install Python
In order to check your work in the labs of this course you will need to have an application called Python installed on your Linux system.
- Download python3.6 using apt
- When prompted type Y to install the app and its dependencies
- When prompted to specify the name of the host where the TANGO database server is running, just select ok.
- Run the following command to verify that python version 3.6 is installed.
python3 --version
- This may take a while.
- Note: You can leave your VM running from this point on
Checking your Work
- Return to your home directory and run:
ls -al
- List the files in the sample-files directory:
- Run the following command:
links
- Navigate to your ip address using the Links browser; does the website look like this?
- Run the following command; does the output look like this?
python3 --version
- Run this script to automatically check your lab
- If you see the shakespeare.tar.gz file you haven't followed all the directions.
- If you only see the shakespeare.tar.gz file you have successfully completed that section of the lab.
- If the Links browser opens you have successfully installed it.
- If your results match the screenshots, you have successfully completed the lab!