* 1 *
The exercises this week are dedicated to the Linux command line using your Linux account at the student server studssh.iu.hio.no. If you are not able to access this server yet, use the Linux server at UiO, login.ifi.uio.no with the username and password you got from the University of Oslo. For those of you who are familiar to Linux command line, there is an extra challenge and you may also start working at one of the next weeks assignments(at the end of this text).
Complete the following exercises by logging in to your account at the server studssh.iu.hio.no(or login.ifi.uio.no) from any of the Windows PC's using putty and the same username and password as for Windows.
Document the commands your run and the output that appears on the screen.
You may want to use the script-command to do this. Where there is a question, answer it. NB: "print" refers
to displaying something in your terminal, not actually printing it out
on paper.
Use Matt Disneys Linux
crashcourse as an instructional reference. Another resource is
Mark Burgess book:
The unix programming environment
(pdf)
(some more exercises for a Unix crashcourse are located at
http://www.iu.hio.no/~haugerud/unix/ if you need more practice. You should start on week 2, since some parts of week 1 is assuming a GUI.)
Usually you will submit weekly assignments as a group, but this weeks assignment should be submitted
individually. Submit using fronter(wait till your fronter room is available).
- Read the manual page for the script command by man script.
If you run the command script week1.txt everything you type and its output will
be stored in the file week1.txt. Find out how to stop the script session.
- Access the manual page for the ls command. What does the -l option do?
- Print your working directory (your current location in the filesystem)
using the command pwd.
- Change to the root ( / ) directory using
cd. Confirm your location using pwd.
- Change back to your home directory.
- Go to the directory /usr/bin using absolute path.
- Go to your home directory. The go to the directory /usr/bin using relative path.
- Run ls. Now run ls -a. What is the
difference in these two commands?
- Make a new directory using the command mkdir myfolder. Verify
that it exists using one or more of the commands you learned earlier.
- Remove the directory you just created using the command rmdir myfolder.
Verify that it no longer exists.
- Create a new file by using the jed editor: jed myfile. (If jed is not installed, use emacs, pico or nano). Type "Hello world!"
in your text document. Be sure to save it.
- Use the utility cat to view the new file you just created.
-
Use the utility cat to view the file ~dstud/twocolpaper.tex. (At login.ifi.uio.no, view
the file ~haarekh/twocolpaper.tex).
What do you think the ~ represents?
- Now use the utility less to view the same file. What is the difference between
cat and less?
- Copy that file to your home directory using the command cp.
- Create a new directory called testdir. Confirm that it exists.
- Move the twocolpaper.tex file to your new directory using
the utility mv. Confirm that the move worked.
- Use the utility rmdir to remove the testdir directory. Why does
that not work? What command will enable you to remove that directory?
- Use the command echo hello to print out the word hello.
- Use the same command, but add the following to create a file containing the word hello: "> hellofile". Confirm that your new file contains the appropriate text.
- Use the command "echo" to print the value of the SHELL variable.
- Assign your first name to the variable NAME. Use echo to print it.
- Use the editor jed to create a new file with some text of your choice: jed mytextfile.
- Now run the command jed MyTextFile. Where are the contents of the file you created in the previous step? What happened?
- Determine how to display the date for the Orthodox Easter using the ncal. Put this command in a text file called myscript. Run sh myscript. Congratulations, you have written your first shell script!
- Create a shell script blah.bash which does the following things:
- Assign "/etc/default" to a variable
- Using ls and your new variable, output the list of files in /etc/default to the file blah.txt.
- Change the file permissions of blah.bash so that the
owner has all permission to to anything (and can run it by $
./blah.bash), the group may read and run it and all others may
just read the file.
- Challenge: Using the output from /sbin/ifconfig,
assign the IP-address of studssh to the variable $IP.
Write a short report answering the questions in a textfile.
Answer all the questions and submit them using classfronter(log on at
http://www.hio.no/fronter and choose engelsk(english) as language),
using the folder "Obligatory assignment, 1st week". Any format is
accepted, preferably PDF or ascii-text. If you submit using a editable
format, like ascii, odt or doc, you may receive comments within the
text from the teachers. Submit both your script and the output file.
Extra challanges for the command line savvy (not obligatory, but interesting!)
-
Find whitch program is started when you give the
commands ls. (hint: Try $ type ls).
Edit a file in your home directory with jed
and call it ls. Write in the following shell-script:
#! /bin/bash
ls
Make the script runnable with the commmand chmod 755 ls.
Write the command
ls in the shell. Is it "your" or the system ls that is
executed? Add the line
echo This is my ls script.
to your ls.
run the ls-command again and try to make the system list the files
with your script.
- Make your own traceroute-command by writing a short bash script which utilizes
the response to ping-packets with an increasing TTL-value, starting from one:
ping -w 1 -c 1 -t 1 vg.no | grep icmp
The output could be similar to this
studssh$ mytrace vg.no
1 From cadeler30-gw.uninett.no (128.39.74.1) icmp_seq=1 Time to live exceeded
2 From pil52-gw.uninett.no (158.36.84.21) icmp_seq=1 Time to live exceeded
3 From stolav-gw.uninett.no (128.39.0.73) icmp_seq=1 Time to live exceeded
4 From ge-0-2-0.br4.osls.no.catchbone.net (193.156.120.3) icmp_seq=1 Time to live exceeded
5 From ge-0-1-1.cr1.osls.no.catchbone.net (193.75.3.6) icmp_seq=1 Time to live exceeded
6 From v99.rs2.sand.no.catchbone.net (193.75.3.1) icmp_seq=1 Time to live exceeded
7 From 193.69.165.11 icmp_seq=1 Time to live exceeded
8 64 bytes from 193.69.165.21: icmp_seq=1 ttl=249 time=1.31 ms
studssh$
From next weeks assignments: tcpdump 2
If you have finished this weeks assignments, you may start working on one of next weeks assignments. But do not submit it till next weeks submission
- Download this file to studssh using wget: http://www.iu.hio.no/~kyrre/flab/tcpdump_2.out. At studssh tcpdump is /usr/sbin/tcpdump and you might need to store the file to local disk (/tmp) in order to be able to read it using tcpdump -r.
- Use tcpdump and wc -l to find out the following:
- Number of packets sendt in total.
- Number of packets sendt from 10.0.0.2
- Number of TCP SYN+ACK packages
- Take a closer look at the file like this: tcpdump -n -r
tcpdump_2.out | less
What is happening in this output? How could an intrusion detection
system detect it?
-
Write a set of UNIX commands that would print out every target port
used. Use this to determine how many ports were tried.