Midterm exam exercises. March 22 2017. Time 3:20 p.m. -- 4:40 p.m.

The exercises are supposed to be done by each student solely on his/her desktop station in the Linux lab, D-112. It is allowed to use the lecture notes at http://linuxcourse.rutgers.edu and any printed material as well as internet web sites.
Number of exercises: 4. Each exercise has a maximum score.
In home directory of user hostadm, you need to create a new subdirectory, MIDTERM and a file within it, answers.txt, where you will be writing answers to the exam exercises.

Hint: if you happen to need to install a software package, run
apt-get install package_name
If you need to inquire about some command, use man on the command name. For example, man tar shows you the information about command tar.

1. VM deployment in KVM (max score 4)
Download a tar ball with a VM from the following link: http://192.168.5.240/coursefiles/midterm2017.tgz
A) Deploy midterm2017 VM in KVM and show the commands you used for that.
B) What is the IP address of the VM?
C) Change the host name of the VM to vmidterm. Explain how you did it.

-- ANSWER
A)
wget http://192.168.5.240/coursefiles/midterm2017.tgz
tar -zxvf midterm2017.tgz
mv midterm2017.img /home/hostadm/KVM
cp midterm2017.xml /etc/libvirt/qemu
chown hostadm:hostadm /etc/libvirt/qemu/midterm2017.xml
chown hostadm:hostadm /home/hostadm/KVM/midterm2017.img
virsh define /etc/libvirt/qemu/midterm2017.xml
B) On the VM, run ifconfig command:
 ifconfig -a
shows the IP address for interface ens3.
C) Edit file /etc/hostname and replace the current host name in it with vmidterm, or just run commend
echo vmidterm > /etc/hostname




2. NFS (max score 6)
There is NFS server running on midterm2017 VM.
A) What file system does it share and with what hosts and/or subnets?
B) Mount the NFS file system onto your desktop. Show the commands you need to use.
C) Create directory MIDTERM in the NFS mounted file system.

Answer
A) In file /etc/exports you can see the exported directory: /usr/exports
B) First, install the NFS client packages on the desktop:
apt-get install rpcbind nfs-common
Create a mounting point, for example /NFS, then run command mount:
mkdir /NFS
mount 192.168.122.50:/usr/exports /NFS 
C) Change the ownership of /usr/exports to user hostadm on the NFS server, midterm2017
chown hostadm /usr/exports
Note, the uid for hostadm should match on both the desktop and the NFS server, midterm2017.
On the desktop, create the directory:
cd /usr/exports 
mkdir MIDTERM 


3. Command find (max score 6)
Download archive.tgz from http://linuxcourse.rutgers.edu/Midterm/archive.tgz.
In the archive, find the full path to
A) file ni_filters.c
B) directory bscript
C) the largest file in the archive.

Answer
A)
wget http://linuxcourse.rutgers.edu/Midterm/archive.tgz
tar -zxvf archive.tgz
find archive -name ni_filters.c
archive/scipy/ndimage/src/ni_filters.c
B)
find archive -type d -name bscript
archive/tools/osx/bscript
C)
find archive -size +5M -ls
find archive -size +4M -ls
13767064 4412 -rw-r--r-- 1 hostadm  hostadm  4513910 Jul 25  2016 archive/scipy/special/cython_special.c
find archive -size +3M -ls
From the output, we pick the largest file, archive/scipy/special/cython_special.c
13634326 3612 -rw-r--r-- 1 hostadm  hostadm   3697269 Jul 25  2016 archive/scipy/linalg/cython_lapack.c
13766938 3676 -rw-r--r-- 1 hostadm  hostadm   3761925 Jul 25  2016 archive/scipy/special/_ufuncs.c
13767064 4412 -rw-r--r-- 1 hostadm  hostadm   4513910 Jul 25  2016 archive/scipy/special/cython_special.c


4. User accounts and SSH (max score 6)
A) Create user account grader on your desktop.
B) Install openssh-server on your desktop.
C) The user's ssh public key is available at http://linuxcourse.rutgers.edu/Midterm/grader_rsa.pub.
Import the public key so user grader will be able to ssh to your desktop by using the public key authentication.
Ask the instructor to test if he can ssh to your desktop as user grader without a password.

-- ANSWER:
A)
adduser grader 
B)
apt-get install openssh-server
C)
su grader 
cd ~grader
wget linuxcourse.rutgers.edu/Midterm/grader_rsa.pub
mkdir .ssh
cp grader_rsa.pub .ssh/authorized_keys