Page |1 Qassim University College of Computer Laboratory Booklet CSC414: Fundamental of Linux/Unix Page |2 Table Of Contents Acknowledgment ……………………………………………………………………………………….……….…………..… 2 Lab Rules and Regulations …………………………………….……………………………………….……...…………..… 3 Tasks and Lab Grading Policy ……………………………………………..………………………….....……….…..… 3 Lab Exercises Exercise 1: REVIEW LINUX COMMANDS………….……………………………………………..……………….…....… 4 Exercise 2: Familiarity with vi editor…….………….…….……………………………..……………………….….6 Exercice:3:Basic Shell Scripting…………………………..............………….………………………………………7 Exercise: 4:Shell Scripting …………………………………………………………………….……………………………8 Exercise: 5 :Shell Scripting …………………………………………………………………………………………………9 Exercise: 6 :Shell Scripting ………………………………………………………………………………………………..10 Exercice: 7:Package Management..……………………………………………………………………….…..……..11 Exercice: 8: Process Management……………………………………………………………………………………..13 Exercice: 9: Disc Management and Quotas ……………………………………………………………………..15 Exercise: 10 : User Management .………………………………………………………………………………………20 Exercice:11 : Scheduling Tasks and Managing Backups………………………………………………………26 Exercice: 12 : Config ring Printers …………………..…………………………………………………………………30 Exercice :13 : Network Configuration ……………….………………………………………………………………32 Exercice: 14 :Security……………………………………………..…………………………………………………………33 Soft Copy is available on the link given below: http://group/CSC414_BY_PRINCE/files/ Lab Exercise.docx Page |3 LABORATORY POLICY AND GUIDELINES Lab Rules and Regulations . . . . . . . . . . . . The students should work individual. Students are strictly prohibited from taking out any items from the laboratory without permission from the Lab Supervisor. The lab timetable must be strictly followed. Prior permission from the Lab Supervisor must be obtained if any change is to be made. Be punctual for your laboratory session. Experiments must be completed within the given time. All students are liable for any damage to equipment due to their own negligence. Static sensitive devices should be handled carefully. All equipment, apparatus and tools must be RETURNED to their original place after use. Students are NOT allowed to work alone in the laboratory. Please consult the Lab Supervisor if you are not sure how to operate the laboratory equipment. Report immediately to the Lab Supervisor any damages to equipment, hazards, and potential hazards. Please refer to the Lab Supervisor should there be any concerns regarding the laboratory. Tasks and Lab Grading Policy . . . Each student make a note after completing of each assignment. This note is part of the evaluation. The students should answer the lab instructor’s questions separately. Page |4 1. REVIEW LINUX COMMANDS OBJECTIVES Revise some useful Linux command. EXERCISE 1. The path locating commands a. b. To know the current path: To set path: $echo $PATH $PATH =/user/local/bin:/user/bin 2. To create a file. a. b. c. $vi filename b. $cat > filename $touch filename (redirection operator) 3. The Archival Program a. $tar –cvf archive.tar file1.html file.ps b. c. d. e. (-c creates an archive, -v display the progress, -f specifying the name of the archive) $tar –xvf archive.tar (extract files from archive) $tar –tvf archive.tar (display file in archive) $tar –cvzf archive.tar.gz file1 file2 (LINUX: Compress also as well as archives) $tar –xvzf archive.tar.gz (LINUX: Decompress also as well as extracts) Note: -Only one option can be used at a time from –c, -x and –t. 4. The compression program a. b. c. d. $gzip –l file1 .gz $gunzip file1 .gz $gzip –d file1 .gz $gzip archive.tar e. $gunzip archive.tar.gz 5. Searching for a Pattern (compressing file1, .gz is not necessary) (uncompressing a gzipped file) (same as above) (compress an archived file, useful for sent out by FTP, or email attachment) (retrieves archive.tar) Page |5 a. $ b. $ c. $ grep “sales” emp.lst (display lines containing the string sales from the file emp.lst) grep “sales” emp.lst emp2.lst grep –v “sales” emp.lst (play inverse role) 6. Pipes a. $ who > user.txt | wc –l <user.txt (counts number of users corrently logged into the system) 7. Byte –by-Byte Comparison a. $ cmp group1 group2 8. What is Common a. b. c. d. $ $ $ $ sort group1>group1.sorted ; sort group2> group2.sorted comm group[12].sorted (options are -1, -2, -3) comm -3 foo1 foo2 (selects lines not common to both files) comm -13 foo1 foo2 (selects lines present only in second file) 9. Converting one file to Another a. $ diff group[12] 10. Displaying Head and Tail of a File a. $ b. $ head –n 3 group1 tail –n 3 group1 Page |6 2. Familiarity with vi editor OBJECTIVES To be familiar with vi editor EXERCISE Exercise 4: 1. List all the mode of vi editor, and how can we activate each mode. 2. List commands for the following under the editor. a. b. c. d. e. Delete a line. Delete a word and character after & before the current cursor position. Cursor movement commands (up, down, right, left). Command to reach beginning and end of the line. Saving and quit without saving (abound) of a document. 3. Get into the vi editor and type some text then save the file with the name myfirstlinuxfile. Page |7 3. BASIC SHELL SCRIPTING OBJECTIVES Command Line Arguments Understanding if statement, for loop, while loop. Basic input and output function. EXERCISE NOTE: Write Shell Script for the following before writing any script make your current directory your home directory (use cd command without argument to do this): Exercice 3: 1. Write a shell script that simulates the cp command. (It should take exact two arguments) 2. Write a shell script that accepts a file name, starting and ending line numbers as arguments and displays all the lines between the given line numbers. 3. Write a shell script to add all the numbers given as arguments. 4. write a shell script that checks if the argument is a prime number or not. 5. Write a shell script that accepts two integers as its arguments and computes the value of first integer raised to the power of the second integer. 6. Write a shell script that computes the gross salary of an employee according to the following. 1) if basic salary is <1500 then HRA 10% of the basic and DA =90% of the basic 2) if basic salary is >1500 then HRA 500 and DA =98% of the basic The basic salary is entered interactively through the key board. 7. Write a script to determine whether a year is leap or not. Page |8 4. SHELL SCRIPTING OBJECTIVES Understand the basics of system calls Use of Library functions. Understanding case-esac.. EXERCISE NOTE: Write Shell Script for the following before writing any script make your current directory your home directory (use cd command without argument to do this): Exercise 4: 4. Write a shell script that accepts a file name starting and ending line numbers as arguments and displays all the lines between the given line numbers. 5. Write an interactive file handling shell program. Let it offer the user the choice of copying ,removing ,renaming or linking files. Once the use has made a choice, have the program ask the user for necessary information, such as the file name ,new name and so on. 6. Write a shell script which receives two files names as arguments. It should check whether the two file contents are same or not. If they are same then second file should be deleted. 7. Write a shell script that displays a list of all files in the current directory to which the user has read write and execute permissions 8. Develop an interactive script that asks for a word and file name and then tells how many times that word occurred in the file. 9. Write a shell script to perform the following string operations. 1) To extract a sub string from a given string 2) To find the length of a given string Page |9 5. SHELL SCRIPTING OBJECTIVES Becoming Familiar with LINUX Commands Using commands into shell the script EXERCISE NOTE: Write Shell Script for the following before writing any script make your current directory your home directory (use cd command without argument to do this): Exercise 5: 1. Determine your login shell and change it to BASH and determine your current path and set it for your home directory. (and if it is already BASH) 2. Use the who command and redirect the result to a file called myfile1 and display the contain of myfile1. 3. Verify that you are in your home directory, make the directory named mydir under your home directory, enter into mydir and verify that you are into the myfile directory. 4. Make a file named testfile under mydir, verify that the file testfile exists and list the contents of the file testfile to the screen. 5. Make a copy of the file testfile with the name secondfile, verify that the files testfile and secondfile both exist, list the contents of both testfile and secondfile to the monitor screen. 6. Delete the file testfile, verify that testfile has been deleted, clear the window. 7. Enter into mydir rename secondfile to thefile, copy thefile to your home directory, remove thefile from the current directory, verify that thefile has been removed. 8. enter into mydir, copy thefile from your home directory to the current directory, verify that thefile has been copied from your home directory to the current directory. 9. Change directories to your home directory, verify that you are in your home directory, verify that a copy of thefile is in your home directory. 10. Remove thefile from your home directory, remove thefile from the directory mydir, remove the directory mydir from your home directory with the following command. 11. Verify that thefile and mydir are gone from your home directory. P a g e | 10 6. SHELL SCRIPTING OBJECTIVES Setting up file attribute through shell programming Creating Hard and Soft link Comparing two files EXERCISE NOTE: Write Shell Script for the following before writing any script make your current directory your home directory (use cd command without argument to do this): Exercise 5: 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. Make a file myfile under your home directory from command prompt. Write access permission of the myfile for each category of the user. (owner, group, other) and change access permission of myfile as execute & write for owner, write for group and only read for others and verify the new permission. Create a hard link for the myfile, verify number of link for the myfile. Create symbolic (soft) link for the myfile, verify number of link for the myfile. Change ownership of myfile to the other user named user2. Now login as a user2. Change group of myfile to the other group named group2, verify the new owner and group of myfie. Display total number of directory in the current directory. (use pipe) From command prompt, make two files file1 and file2 under each file list name of some cities duplicate some cities and some cities should be common in both the files. Sort file1 in ascending order and file2 in descending order, count how many time ‘qasim’ occurs and display lines not common in both the files.. P a g e | 11 7. Package Management OBJECTIVES Define what a package is and describe how it is used. Install, upgrade, delete, verify, and query packages on your system. Determine which package a file is located in. Compile and install programs from source. Define and manage shared libraries. EXERCISE Exercise 7-1: Verify the Installation of the Package 1. 2. 3. 4. Using rpm, check the version of the installed package. .................................................................................................................................... .................................................................................................................................... Once again with rpm, list all of the installed packages. .................................................................................................................................... .................................................................................................................................... Use rpm to display information for a specific package. .................................................................................................................................... .................................................................................................................................... Verify all installed packages using the verify option. .................................................................................................................................... ............................................................................................................................... Exercise 7-2: Verify the Location of the Database 1. . Verify the location of the RPM database for the grip package using the rpm command and the verify option. .................................................................................................................................... ................................................................................................................................... Exercise 7-3: dpkg/dselect dpkg 1. 2. Install the Debian package zsh_3.1.2-10.deb, located in the Supplemental Files directory of the Interactive Learning CD-ROM. .................................................................................................................................... .................................................................................................................................... Remove the zsh_3 package. Make sure to remove all remnants of the package as well, ncluding the configuration files. P a g e | 12 HINT: There is a command for this action. 3. .................................................................................................................................... .................................................................................................................................... Queue the database by listing the installed packages by name. .................................................................................................................................... .................................................................................................................................... dselect 1. Open the dselect utility. .................................................................................................................................... .................................................................................................................................... 2. Select the option that allows you to choose the method of access. Choose the selection that allows the CD to be the method of installation. 3. .................................................................................................................................... .................................................................................................................................... Update the list of possible packages. 4. .................................................................................................................................... .................................................................................................................................... Install the available packages. .................................................................................................................................... ............................................................................................................................... P a g e | 13 8. Process Management OBJECTIVES Perform basic process, memory, and performance management. (Use basic utilities such as ps, kill, kill all, and free.) Create, monitor, and kill processes. Modify process priorities. Explain how to get around a locked-up program. Describe how daemons work, and how buffer overflow problems can affect security. Manage memory and CPU usage. Explain the use of core dump files and how to prevent them from being created. Configure and use process accounting. EXERCISE Exercise 8: 1. Write shell script to perform following tasks. a. b. c. d. e. f. g. 2. Write shell script to perform following tasks. a. b. c. d. e. f. 3. List the processes for the current shell. Display information about processes. Display the global priority of a process and find out the column that provides. Change the priority of a process with default argument. Display virtual memory statistics. Display System Event Information. Display Swapping Statistics. Check File Access statistics. Check Buffer Activity Statistics. Check Disk activity statistics. Check Inter Process Communication statistics. Check unused Memory in the server. Check swap activities. You have three programs that have locked up. Running ps ux shows the following: USER PID %CPU %MEM VSZ RSS TTY STAT START TIME cbuchek 692 cbuchek 728 0.0 0.0 1.2 0.7 ? pts/1 S S 08:59 09:58 0:04 0:00 3908 1760 1636 996 smbd -D -bash COMMAND P a g e | 14 cbuchek 893 booch booch 0.0 14463 14464 0.7 99.9 0.0 2664 0.7 0.0 952 720 0 pts/1 220 0 R p2 p2 13:16 R Z 0:00 19:23 19:23 ps ux 8:41 0:00 ./a.out (a.out <zombie>) What is the PID of each of these processes? What is the state of these processes? .................................................................................................................................... .................................................................................................................................... 4. You have made a change to the configuration file of a daemon called xyzd. However, the daemon does not seem to recognize the changes. What can be done to make the daemon reread the config file? .................................................................................................................................... .................................................................................................................................... 5. You are running a make command that spawns and runs other child make commands, and it is starting to bog the CPU (since compilations tend to be CPU intensive). How can this be stopped? . ................................................................................................................................... .................................................................................................................................... 6. How can you show what program has been run the most times since the system was ast rebooted? .................................................................................................................................... .................................................................................................................................... 7. Tom started a process with the nice command, giving it an initial priority value lower than the system default (indicating that his process is a lesser-priority process). He later realizes that due to his initial assignment, his process takes forever to complete, and he decides to change it to the default priority. What should Tom do to alter the priority? .................................................................................................................................... .................................................................................................................................... P a g e | 15 9. Disk Management and Quotas OBJECTIVES At the completion of this chapter, you will be able to: Manage file ownership and permissions. Set, manage, and view disk quotas. EXERCISE Exercise 9-1: File Permissions 1. The following is a session: $ id –a uid=318(hawkeye) $ ls -ld . drwxr-xr-x -rw-rw-r--rw-r-----rw-rw-rw-r--r--r--r-------drwxrwxr x gid=300(users) groups=100(staff), file* /etc/passwd /etc/shadow /etc 2 trapper users 512 1 trapper staff 23 1 trapper mash 41 1 hawkeye mash 41 1 root sys 132 1 root sys 96 49 root sys 4096 Jul Jul Jul Jul Jan Jan Jan 11 15 15 15 01 01 01 300(users) 11:21 . 10:21 file1 10:21 file2 10:21 file3 9:30 /etc/passwd 9:30 /etc/shadow 9:30 /etc Which of the following operations are permitted? $ more file1 $ more file2 $ ls -l >file1 $ more /etc/passwd $ more /etc/shadow $ rm file2 $ rm file3 $ cp file1 file4 $ rm /etc/passwd $ rm /etc/shadow 2. Write a shell script which accept the name of a file from the standard input and then perform the following test on it. a. File Existence b. File Readable and Writable P a g e | 16 3. Write a shell script which receives two files names as arguments. It should check whether the two file contents are same or not. If they are same then second file should be deleted. Exercise 9-2: Working with the quota Utilities 1. Modify the following line in /etc/fstab to allow for user and group quotas: /dev/hda1 /home ext2 defaults 1 2 .................................................................................................................................... .................................................................................................................................... 2. Examine the following example output from edquota -u tempuser: Quotas for user tempuser: /dev/hda2: blocks in use: 6502, limits (soft = 8000, hard = 10000) inodes in use: 814, limits (soft = 2000, hard = 2500) Write the command to duplicate this quota for every user in the tools group. .................................................................................................................................... .................................................................................................................................... 3. Using one of the commands in the quota suite of programs, write the command to obtain a listing of all quotas set on a machine. .................................................................................................................................... .................................................................................................................................... 4. What daemon would allow for obtaining quota information from remotely mounted directories? ................................................................................................................................... .................................................................................................................................... . 5. Write shell script to perform following tasks. a. b. c. d. e. f. g. Create a file under user home directory in the name of quotas. Change the ownership of the file. Make an entry in rq in the /etc/vfstab. Turn on the quotas by uasing quotaon command. Assign the quota for user by using edquota command. Check the quota for the file system. Turn off the quota. Exercise 9-3 File Systems 1. Create an ext2 file system on a 200-MB disk hda5. .................................................................................................................................... P a g e | 17 .................................................................................................................................... 2. . Mount this file system on /usr. .................................................................................................................................... ................................................................................................................................... 3. Create an ext2 file system on a 150-MB disk hda6. .................................................................................................................................... .................................................................................................................................... 4. Mount this file system on /usr/lib. Create this directory if it does not already exist. .................................................................................................................................... .................................................................................................................................... 5. Create a minix file system on 100-MB disk slice hdb2 and mount on /home. .................................................................................................................................... .................................................................................................................................... 6. Unmount all three file systems; notice that you must unmount /usr/lib before you can unmount /usr. .................................................................................................................................... .................................................................................................................................... 7. Write shell script to perform following tasks. a. b. c. Identify the available memory in the system. Display the list of devices connected to your system including the physical name and its instance number. Identify the number of hard disk connected to the system. Exercise 9-4 Identifying Lost Files Given the following lost+found directory: # cd /home/lost+found # file * 000541: ASCII text 000872: commands text 001065: iAPX 386 executable not stripped 001085: C source code 001461: data which command(s) would you use to identify the contents of each file? To identify file 000541? .................................................................................................................................... .................................................................................................................................... P a g e | 18 To identify file 000872? .................................................................................................................................... .................................................................................................................................... To identify file 001065? .................................................................................................................................... .................................................................................................................................... To identify file 001085? .................................................................................................................................... .................................................................................................................................... To identify file 001461? .................................................................................................................................... .................................................................................................................................... Exercise 9-5: Examining and Checking File Systems Write the commands to perform the following: 1. Set the maximum mount count on /dev/hda3 between bootup fscks to 20. .................................................................................................................................... .................................................................................................................................... 2. . Give two commands to check for bad blocks on /dev/hda2 (with 65,535 blocks). ................................................................................................................................... .................................................................................................................................... 3. Show the process (without acutal execution) for a file system check of all file systems listed in fstab. .................................................................................................................................... .................................................................................................................................... 4. Execute a verbose file system check on /dev/hda3 with progress bars, specifying the vfat file system. ................................................................................................................................... .................................................................................................................................... . Exercise 5-6: Using mount with NFS 1. What command will mount /usr/share from mash4077 on the local mount point /usr/share with background mount and timeout? .................................................................................................................................... .................................................................................................................................... 2. Fill in the mount options for the following two /etc/fstab files: P a g e | 19 # grep home /etc/fstab rosies:/home/rosies /home/rosies nfs 0 0 # rsh rosies grep home /etc/fstab mash4077:/home/hawkeye /home/hawkeye nfs 0 0 .................................................................................................................................... ............................................................................................................................... P a g e | 20 10. User Management OBJECTIVES Create user accounts. Manage user and group accounts and related system files. Set up user-level security. Customize and use the shell environment. Tune the user environment and system environment variables. Create user and system profiles. Use basic user commands. Describe the distinction between user, group, and other. EXERCISE Exercise 10-1: Adding and Modifying Users Write down the commands used to perform the following. 1. Add a user called frank. .................................................................................................................................... .................................................................................................................................... 2. Add a user called radar specifying the Korn shell. .................................................................................................................................... .................................................................................................................................... 3. Add a user called klinger using /home2/klinger as the home directory. .................................................................................................................................... .................................................................................................................................... 4. Add a user called mulcahy specifying a UID of 400 and a group of staff. .................................................................................................................................... ................................................................................................................................... . 5. 6. Modify the user frank to use the korn shell. .................................................................................................................................... .................................................................................................................................... Modify radar to give him a new UID of 401. .................................................................................................................................... .................................................................................................................................... Exercice 10-2: Account Security P a g e | 21 Write down the commands used to perform the following. (You may need to read the man pages for syntax and options.) 1. Add a password for user frank. .................................................................................................................................... .................................................................................................................................... 2. Force frank to change his password at next login. .................................................................................................................................... .................................................................................................................................... 3. Enable password aging for trapper (min 21 max 31 warn 7). .................................................................................................................................... .................................................................................................................................... 4. . Set the expiration date for hawkeye to 31 Dec 1999. ................................................................................................................................... .................................................................................................................................... 5. Lock henry’s account. .................................................................................................................................... .................................................................................................................................... 6. Unlock henry’s account. .................................................................................................................................... .................................................................................................................................... Exercise 10-3: Managing Users 1. Use useradd to add a new user called hawkeye (full name Pierce) with a user ID of 318. Don’t forget to use the -m option to create the user’s home directory. Set a password for this account and force this password to expire the next time the user logs in. Test your new account first by using su and then by logging out and back in again as the new user hawkeye. .................................................................................................................................... .................................................................................................................................... 2. Correct the full name for user hawkeye to be B F Pierce and give him /bin/bash as his login shell. .................................................................................................................................... .................................................................................................................................... 3. As root, use chage –l to show the status of hawkeye’s password protection. Change the password aging to: Maximum number of days: 7 Minimum number of days: 2 P a g e | 22 Warning number: 7 Log in as hawkeye and try to change the password. If you cannot, su to root and fix the problem. Exit from the root shell and change the password for hawkeye. .................................................................................................................................... .................................................................................................................................... 4. Create a new group called swamp. Modify hawkeye to be a member of group swamp; do not modify hawkeye’s default group. In one command, add a new user trapper with full name J F X McIntyre, user ID 319, and membership in the supplementary group swamp (leave the user’s default group as its default value). Set a password for trapper and log out. Verify that you can log in as trapper correctly and, as trapper, enter the following commands: $ batch date ^D This will ensure that there is a mail message for trapper. Do not read this mail message yet; we want it to remain in the mailbox. .................................................................................................................................... .................................................................................................................................... 5. Remove the account for trapper, including the home directory. Now find out if trapper still owns any files on the system. Use useradd to re-create the trapper account with the same parameters as before. You will not be able to do this because the system will not let you reuse the 319 user ID for another 20 days. What command option should you have specified to ensure that you could reuse the 319 user ID? .................................................................................................................................... .................................................................................................................................... 6. List all of the groups that root is a member of (don’t forget the default group). .................................................................................................................................... .................................................................................................................................... Exercice 10-4: Managing User Home Directories 1. Create a directory called /home/skeleton, which contains all of the files in /etc/skel (note that there will be hidden files in /etc/skel). Create two empty files called footlocker and uniform in /home/skeleton. Create a new account for frank (full name F M Burns, user ID 320) with a skeleton directory of /home/skeleton. Verify that the correct files are in /home/frank. .................................................................................................................................... .................................................................................................................................... P a g e | 23 2. Add a new account for hotlips (full name M Houlihan, user ID 321) but do not make the home directory. Set a password for hotlips’ account and verify the account with: # su - hotlips # pwd What is your working directory shown by the last command? Why isn’t this /home/hotlips? Log out and try and log in as hotlips. You will not be able to do so because the home directory doesn’t exist. Log in as root and manually create the home directory for hotlips using /home/skeleton as a skeleton directory. Log in as hotlips and verify that you can put something in your footlocker (i.e., edit the footlocker file). .................................................................................................................................... .................................................................................................................................... 3. Change the user ID for frank to 322. Now enter the following command: # ls -al /home/frank Does everything look correct or did you forget to do something? .................................................................................................................................... .................................................................................................................................... Exercise 10-5: Example Environment Which of these files is maintained by the administrator? /etc/profile /etc/bashrc $HOME/.bash-profile $HOME/.bashrc .................................................................................................................................... .................................................................................................................................... Exercise 10-6: User Environments 1. Use useradd to add a new user called shutdown, which calls the /sbin/shutdown program as its login shell. Note that shutdown must be run from the root directory (/) and must be run by root (user ID 0). Make sure you can shut down the system simply by logging in to this account. You will need to use the -o option for useradd when specifying a user ID of 0 (look in the manual page). .................................................................................................................................... .................................................................................................................................... 2. Add a new user called date that calls the /bin/date program. Set a blank password for this account and test the account using su. .................................................................................................................................... P a g e | 24 .................................................................................................................................... 3. Log in as henry and find out your default value for umask. Where is the umask being set? Enter the following commands: $ mkdir demo $ cd demo $ umask 0 $ touch um000 $ umask 022 $ touch um022 $ umask 077 $ touch um077 $ umask 770 $ touch um770 $ ls -l Look at the different file permissions. Which file permissions do you think you would want to use as a default when creating files? Set the umask accordingly so that the next time you log in this will be your default umask. Make this change and log out and back in again to verify your changes. What is odd about the permissions on the um770 file? .................................................................................................................................... .................................................................................................................................... Exercise 10-7: Restricted User Environment 1. Modify hawkeye’s environment so that he cannot change or delete his profile. .................................................................................................................................... .................................................................................................................................... 2. Test your changes by logging in as hawkeye and verifying that he cannot edit .bash_profile or delete the file. Exercise 10-8: Working with TERM Types What will the user prompt display after the following sequence of bash shell commands? $ tput rev $ tput rmso $ REV=$(tput rev) $ NRM=$(tput rmso) $ PS1=$REV$(uname -n)$NRM: 'echo $PWD: ' .................................................................................................................................... .................................................................................................................................... P a g e | 25 Exercise 10-9: Logins and Terminals 1. Change the login defaults so that the systemwide umask is 077. Make sure that /etc/profile does not override this value and verify your changes. .................................................................................................................................... .................................................................................................................................... 2. Log in as henry and write down the settings for the following special keys described by stty: erase? intr? kill? eof? Change your interrupt key to be CONTROL+A and your kill key to be CONTROL+B. Enter a partial command line and press CONTROL+C. What happened? Press CONTROL+A; what happened this time? Enter a partial command line and press CONTROL+B. What happened? .................................................................................................................................... .................................................................................................................................... 3. Log in as henry and determine your quit character (it is probably CONTROL+BACKSLASH). Run the following command (this should take a long time). Press the quit key at any time. $ ls -lR / Look at the size of the core file that was generated. Enter the following commands: $ rm core* $ ulimit -c 0 Try the first part of the question again and notice the different core file size. .................................................................................................................................... .................................................................................................................................... 4. What is your terminal type set to? Enter the following commands: $ OTERM=$TERM $ TERM=wyse50 $ vi :q! # quit out of vi as everything has gone wrong $ TERM=$OTERM Why was vi unable to draw the screen correctly? .................................................................................................................................... .................................................................................................................................... Be sure to set everything back the way it was before you started the exercise. 5. P a g e | 26 11. Scheduling Tasks and Managing Backups OBJECTIVES At the completion of this chapter, you will be able to: Automate system administration tasks by scheduling jobs to run in the future. Use cron and related tools. Design and maintain an effective data backup strategy. Use tape archive and restore (tar) for archiving and restoring files. Use copy to I/O (cpio) to read and write various archive types. EXERCISE Exercise 11-1: Using cron and at 1. . 2. You should set the VISUAL or EDITOR environment variables before running crontab so that you do not end up with a text editor that you don’t know how to use. Recommended text editors are pico, jed, emacs, and vi. (Note that not all distributions will have all of these installed by default.) .................................................................................................................................... ................................................................................................................................... Edit your cron table using the crontab command. .................................................................................................................................... .................................................................................................................................... 3. Create a cron job to send yourself an e-mail greeting on your birthday. Create another cron job to send yourself an e-mail 10 minutes from now. Make sure that you receive that message. .................................................................................................................................... .................................................................................................................................... 4. Use at to send yourself an e-mail message 5 minutes from now. Make sure that you receive it. Try out some other time formats as well. .................................................................................................................................... .................................................................................................................................... 5. View the at queue and remove some entries. .................................................................................................................................... .................................................................................................................................... Exercise 11-2: Using afio Explain the purpose of the following commands. 1. # find . -print | afio -ovb > /dev/ftape P a g e | 27 .................................................................................................................................... .................................................................................................................................... 2. # afio -tb < /dev/ftape .................................................................................................................................... .................................................................................................................................... 3. # cd /tmp # afio -ivab < /dev/ftape .................................................................................................................................... .................................................................................................................................... 4. # cd / # find etc home var -print | afio -ovb /dev/ftape .................................................................................................................................... .................................................................................................................................... 5. # cd /tmp # afio -ivaby etc/init.d /dev/ftape .................................................................................................................................... .................................................................................................................................... Exercise 11-4: Using tar, gzip, and compress This exercise will deal with the use of tar, gzip, and compress to archive and compress several files in order to create a backup. 1. What is the simplest way to place the contents of the /bin/ directory in a single tar archive named bin.tar? .................................................................................................................................... .................................................................................................................................... 2. Using gzip, how can the archive be compressed to save the most space? .................................................................................................................................... .................................................................................................................................... 3. How can the archive be compressed using compress? .................................................................................................................................... .................................................................................................................................... Can these steps be combined in a simpler way? If so, how? .................................................................................................................................... .................................................................................................................................... 4. 5. How can the gzippped file be uncompressed? How can the compressed file be uncompressed? P a g e | 28 .................................................................................................................................... .................................................................................................................................... 6. What command will expand the uncompressed archive file? .................................................................................................................................... .................................................................................................................................... 7. How can the uncompress and untar commands be executed at the same time? .................................................................................................................................... .................................................................................................................................... Exercise 11-5: Backup and Restore 1. 2. Log in as root and run the following command: # touch /home/backup Change to the /usr directory and back up the dict directory to floppy disk using tar. The floppy disk device is /dev/fd0. Why do you think you were asked to change directory and back up disks as two separate actions? How would you verify that the backup worked? Restore the backup into the /tmp/dict.tar directory. .................................................................................................................................... .................................................................................................................................... 3. Repeat the previous backup and restore using cpio (restore to /tmp/dict.cpio). .................................................................................................................................... .................................................................................................................................... 4. If you didn’t know what format of data was written to the floppy disk, how would you find out? .................................................................................................................................... .................................................................................................................................... Exercise 7-6: Timing Backups (Optional) 1. Repeat the backup operations from steps 2 and 3 in Exercise 7-5, first using tar and then cpio, but time the operation using the time command as in the following examples: # cd /usr # time tar cvf /dev/fd0 dict # time (find dict -print | cpio -ocv >/dev/fd0) Why do you think we used parentheses in the second example? .................................................................................................................................... .................................................................................................................................... 2. Repeat the two backups again, but this time output to files /tmp/tar and /tmp/cpio rather than to the floppy disk. P a g e | 29 Repeat again, but this time make tar and cpio write to standard output, pipe this through the compress command, and redirect the whole thing to files /tmp/tar.Z and /tmp/cpio.Z. The following examples show what is required: # cd /dict # tar cvf - dict | compress >/tmp/tar.Z # find dict -print | cpio -ocv | compress >/tmp/cpio.Z Now compare the sizes of all four archive files. .................................................................................................................................... .................................................................................................................................... 3. How would you back up all of the files that have been modified since /home/backup was created? .................................................................................................................................... .................................................................................................................................... Exercise 11-7: Backup Techniques 1. Put the floppy disk containing a backup into the disk drive and enter the following commands: # dd if=/dev/fd0 count=1 of=/tmp/fd # file /tmp/fd What do you think you have just done? .................................................................................................................................... .................................................................................................................................... 2. Format your floppy disk with a DOS file system. Copy the hosts file onto this floppy disk. Take a directory listing to prove it’s there. Now copy this file back to /tmp and call it DOS.hosts. Look at this file to make sure it’s valid. Copy the entire floppy disk to a file called /tmp/dos.fd. Enter the following command to corrupt the DOS diskette: # dd if=/usr/bin/date of=/dev/fd0 Can you get a DOS directory listing from the floppy disk? Now copy your floppy disk image from /tmp/dos.fd onto the floppy disk. Can you get a DOS directory listing from the floppy disk now? .................................................................................................................................... .................................................................................................................................... P a g e | 30 12. Configuring Printers OBJECTIVES At the completion of this chapter, you will be able to: Manage printers and print queues. Install and configure local and remote printers. Explain the LPD printing system. Configure the printer control file (/etc/printcap). Configure printer filters. EXERCISE Exercise 12-1: Configuring and Using a Network Printer In this exercise, you will configure a network printer and share it among several systems. A system with a printer directly attached will be set up as a print server. To any other system, this printer is a network printer; to this system, it is a local printer. Any other system will be referred to as a client of the print server. Solutions to this exercise are provided in Appendix B at the end of this manual. 1. Working on the print server, verify that you can send data to the printer and that it prints. .................................................................................................................................... .................................................................................................................................... 2. On the print server, configure the local printer using printtool. Print a small test job (the /etc/passwd file is a good test). .................................................................................................................................... .................................................................................................................................... 3. On a client, add a network printer using printtool. Print a small test job (the /etc/passwd file is a good test). .................................................................................................................................... .................................................................................................................................... Exercise 12-2: The Print Queue 1. On your system, either client or server, disable your print queue. .................................................................................................................................... .................................................................................................................................... 2. Print three different files (remember the order you printed them in). Look at the outstanding print jobs with lpc -status and lpq. P a g e | 31 .................................................................................................................................... .................................................................................................................................... 3. Set the last job to be the next job to print. .................................................................................................................................... .................................................................................................................................... 4. Cancel the middle job using lprm. .................................................................................................................................... .................................................................................................................................... 5. Cancel all of the jobs using a single lprm command. .................................................................................................................................... .................................................................................................................................... P a g e | 32 13. Network Configuration OBJECTIVES Manages the system network Remote login (telnet and ssh Transfering file using ftp server EXERCISE Exercise: 13-1 1. 2. 3. 4. 5. Display information of all currently active interfaces. (ifconfig –a) Log in to a remote network workstation across the directly connected network. (telnet). Log in to a remote host with your local user name. (rlogin hosh2) Log in to a remote host with a different user name. (rlogin hosh2 –l name2). Resolving Hostnames and IP addresses(cat /etc/hosts). 6. 7. 8. Checking the network($ping earth, interrupted by pressing ctrl-c) Remote login($telnet 192.168.35.12, $[ctrl-]]: telnet session is closed, Execute command on your local machine (telnet> ! ls –l *.sam). P a g e | 33 14. Security OBJECTIVES Set up host security. Explain and implement file system security. Implement password security policies. Use available security tools. Use /etc/securetty to limit locations that root can log in from. Determine whether services should run as root or nobody. Explain the security implications of buffer overruns. EXERCISE Exercise: 14-1 1. 2. 3. 4. 5. . 6. 7. 8. . Create the /usr/local/sbin/fingerd file, containing the following: #!/bin/sh echo "Finger information for this system is not available." Make the /usr/local/sbin/fingerd file executable. .................................................................................................................................... .................................................................................................................................... Edit the inetd.conf file to comment out any previous finger service. Add the following line: finger stream tcp nowait nobody /usr/local/sbin/fingerd .................................................................................................................................... .................................................................................................................................... Force the inetd daemon to reread its configuration file. .................................................................................................................................... .................................................................................................................................... Test the finger service on the system. ................................................................................................................................... .................................................................................................................................... Disable the finger service in the inetd.conf file. .................................................................................................................................... .................................................................................................................................... Have the inetd daemon reread the configuration file. .................................................................................................................................... .................................................................................................................................... Test the finger service again. .................................................................................................................................... ...................................................................................................................................