Copyright: The development of this document is funded by Higher Education of Academy. Permission is granted to copy, distribute and /or modify this document under a license compliant with the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License. To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/3.0/. GNU/Linux: An Essential Guide for Students Undertaking BLOSSOM BLOSSOM Manchester Metropolitan University (Funded by Higher Education Academy) blossomlhan@gmail.com
1. Learning Objectives This lab aims to understand basic operations of Linux system 2. Preparation 1) Under Linux environment 2) Some documents that you may need to refer to: 'Virtual-Machine-Guide.pdf' 3. Tasks Setup & Installation: 1: Start a single virtual machine as you have done with previous exercises (see Virtual Machine Guide) # kvm -cdrom /var/tmp/debian-live-6.0.4-i386-gnome-desktop.iso -m 512 -net nic,macaddr=52:54:00:12:34:57 -net vde -name node-one 2: Use the following set of commands to download everything that is required for the lab, as well as any dependencies required: # apt-get update # apt-get install apache2 Task 1 (LINUX/UNIX File Structure and Commands): 1.1: Whilst LINUX has not been as successful as MAC OS and Microsoft Windows, it has excelled in the server market. The majority, if not all of the services you rely on from day to day, such as email and websites rely on an enormous number of LINUX servers. It is essential for anyone undertaking a computer science based course to have a grasp of LINUX. This document merely provides a basis for the essential commands for you to complete the lab exercises. In *NIX systems (LINUX and UNIX), directories are placed in a hierarchical structure, at the top is /, everything else is placed underneath, regardless of physical location. This may be a difficult concept to grasp if you've come from a Windows background. Physical disks may be mounted underneath this umbrella in any location, to the end user this is completely transparent. On nearly all LINUX based systems, you can expect to find the following directories under /:
Directory bin dev home lib64 and/or lib media opt root sbin sys usr boot etc var mnt proc Typical Contents Program binaries Device files, each physical device is represented by a file User's files Shared libraries 64 and 32 bit respectively Typical location where removable media is mounted Program extras that are not part of the default installation The administrative user's personal files Administrative programs A virtual file system for device settings User applications and other resources required to run them Files needed to boot the operating system Configuration files of programs Variable system data A popular place to mount hard disks A virtual directory that contains information about the kernel So for example, the location of the file that controls the name of the computer is /etc/hostname 1.2 Making files and directories mkdir ~/blossom create a directory under your home directory nano ~/blossom/foobar.txt create a file under blossom directory mkdir ~/blossom/desktop create a directory under the blossom directory 1.3 Copying files from one location to another in Linux can be done very easily with the cp command: cp /home/blossom/foobar.txt /home/blossom/desktop/
Copies foobar.txt from the user blossom's home directory to their Desktop. cp /home/blossom/foorbar.txt./foobarcopy.txt Copies foobar.txt into the same directory, calling the copy foobarcopy.txt cp - r /home/blossom/somedirectory /home/blossom/desktop Copies the entire folder somedirectory to the user's desktop. Try and copy the file /etc/resolv.conf to your home directory. 1.4: Moving files is as simple as copying, if not simpler; the mv program does not require the -r flag when moving directories: mv /home/blossom/foobar.txt /home/blossom/desktop/ Moves foobar.txt from the user blossom's home directory to their Desktop. mv /home/blossom/foorbar.txt./foobarcopy.txt Renames foobar.txt, foobarcopy.txt mv /home/blossom/somedirectory /home/blossom/desktop Moves somedirectory into the Desktop When using a terminal or bash script, it is possible to use 'wildcards' (*) for certain functions, for example: mv /home/blossom/*.txt /home/blossom/desktop/ Moves all.txt from the user blossom's home directory to their Desktop. Try and move the resolv.conf copy that you made earlier from your home directory to your desktop. Another extremely useful command is rm, which will simply remove a file: rm /home/blossom/foobar.txt Removes foobar.txt from the user blossom's home directory Try and remove the file resolv.conf from your desktop. 1.5: There are many text editors available for use in Linux, but the two main recommendations would be either gedit or nano: nano
nano is a command line based text editor. To edit or create a file simply type in a terminal nano followed by the name of the file: nano /foo/bar.config You can save and exit the program by pressing CTRL+X gedit gedit has an extremely intuitive interface, it is invoked the same way as nano. Task 2 Super User, Programs & Daemons 2.1: There is an obvious need to restrict normal users from editing or viewing certain files, such as system configuration files. If you need to become an administrator, you have two options, su and sudo. If you wish to temporarily elevate your privileges, you can prefix your commands with sudo: sudo rm - r /* If you want to become the administrator, then you should use the command su. When asked for the password, simply enter the root users password. All subsequent commands will be executed as root. To exit, type exit. 2.2: To kill a program that you know the name of, use the 'killall' command. For example, to kill a program that uses java, execute: # killall java Use of this command is generally frowned upon, and should be avoided if possible. Kill is the preferred command. Use 'top' to look up the PID (Process ID) of the program you want to kill. Then use: # kill -9 XXXX 2.3: Services, such as apache (a popular web server), can be controlled via two methods: # service apache2 restart # /etc/init.d/apache2 restart Available options are usually: start, stop, restart and reload (which reloads the configuration files in-place).
Task 3 Linux Networking Principles 3.1: Linux is renowned for its excellent, reliable and modular networking facilities. All physical and virtual network interfaces have a name. Ethernet ports are usually named ethx, where X is a number. Wireless devices are usually named wlanx, athx or wifix. lo is the 'loopback' interface, any traffic directed to it is then redirected to the host. You can look up a list of interfaces by calling the ifconfig command: # ifconfig You can view routes using the netstat command: # netstat -r 3.2: You can find the configuration for each interface (on debian systems) in /etc/networking/interfaces. The DNS server setting can be found in /etc/resolv.conf The hosts file, which controls which names are associated with which IP addresses can be found at /etc/hosts Alter /etc/resolv.conf to use 208.67.222.222 and 208.67.220.220, and then restart the networking interface.