Linux Administration (alternative name is Computer Devices and Operating Systems) 5 ECTS

A human being should be able to change a diaper, plan an invasion, butcher a hog, conn a ship, design a building, write a sonnet, balance accounts, build a wall, set a bone, comfort the dying, take orders, give orders, cooperate, act alone, solve equations, analyze a new problem, pitch manure, program a computer, cook a tasty meal, fight efficiently, die gallantly. Specialization is for insects.

- Robert A. Heinlein

Using command line interface, understanding operating system fundamentals, and computer operations are fundamental skills for every IT engineer. Studies in this course are not about specialisation but learning generic and very useful IT skills.

Grading and how to pass the course

Study groups and the Gilligan's Island Rule

Students are encouraged to study and learn together. Another student is often the best resource for working out a complex computation or understanding a difficult concept. However, in (this class) all documents turned in to fulfill assignments must be the exclusive work of the person submitting them, unless otherwise stated. In order to allow students to work together, yet submit assignments that represent their own thought, the Gilligan's Island rule is adopted.

The Gilligan's Island Rule: You are free to meet with fellow students(s) and discuss an assignment with them. Writing on a board or shared piece of paper during the meeting is acceptable; however, you should not take any written (electronic or otherwise) record away from the meeting. Everything that you derive from the collaboration should be in your head. After the meeting, engage in at least a half-hour of mind-numbing activity (like watching an episode of Gilligan's Island*), before starting to work on the assignment. This will assure that you are able to reconstruct what you learned from the meeting by yourself.

* Gilligan's Island was a 1960s sitcom that set the standard for dim-witted TV. Seinfeld or anything more intelligent, e.g. some PBS programming, also works for this purpose.

Source

Example books

Some fundamentals about computers

Optional assignments. No need to document to the learning diary. Ignore for peer reviews:



Raspberry Pi

This is not directly course related assignment but just a quick command list how to make Raspberry Pi to work from read-only file system (Rasbian Linux): raspberry_pi_read_only_filesystem_tuning.txt



Some nice defaults and packages for Ubuntu 22.04 and later servers

This Bash script can be used to install some useful packages and change some server default settings. Completely optional.

$ curl -s -L https://tl.oamk.fi/cdos/dl/install.bash | sudo bash



Course week 1

Linux server extra demos, not much explaining but just doing (in Finnish but it shouldn’t be too hard to follow events):

Assignments to the learning diary. (You can do these in small groups. Still, learning diaries are personal):

Week 1-3 assignments may be boring, but are absolutely critical when using and maintaining Linux servers. Without knowing these commands and concepts, it is close to impossible to learn more. Do not skip these basics!

  1. Install Ubuntu Linux (or whatever Linux distribution you prefer) to VMware, VirtualBox, Hyper-V or KVM (or use Windows 10/11 WSL/WSL2). You can skip this if you are already using personal Linux desktop(s) or server from Oamk
    Note: Virtualbox has often compatibility issues with WSL2
  2. Browse this Linux Command Line Primer
  3. Describe following commands and concepts:
  4. What is the difference between Linux kernel and GNU/Linux distribution?
  5. Name some very common Linux distributions
  6. What is GPLv2/v3 license? And BSD style license?
  7. What is (operating system) shell?
  8. What are case sensitive file names?
  9. Describe common purpose of files and directories in “/etc”, “/usr/bin” and “/var”
  10. What is shell PATH? What is the difference between absolute and relative path?
  11. What is the purpose of tilde character (~) for most Linux shells. For example ls ~/
  12. How do you recognise a hidden file in any common Unix/Linux file systems?
  13. What is the meaning of “piping data between commands”?
  14. What are seti-uid (suid) and set-gid (sgid) bits for file permissions?
  15. What is a “sticky-bit”?
  16. Use manual pages and explain what will command “uname -a” do?
  17. Use manual pages and explain what will command “wc -l” do?
  18. Linux file handling intro:
  19. Remove files and directories which you created on this exercise

Extra assignments (No need to answer to the learning diary. Ignore for grading):



Course week 2

Extra tools:

Assignments to the learning diary (You can do these in small groups. Learning diaries are personal):

  1. Watch some live coding Twitch streams, select one and answer:

  2. If you have a Windows host:

  3. Study and explain shortly following commands and concepts:

  4. Install build-essential meta package (containing development tools) to your server with: sudo apt install build-essential

  5. Get the source code for curses-based (“text-graphics”) worm game nibbles-1.2.tar.gz

  6. Get the source code for another curses-based (“text-graphics”) Tetris game nct-1.4.tar.gz

  7. Download the file harj_zip_paketti.zip. Zip-package has following hierarchy:

    paahakemisto
          hakemisto_a
                karate_kat.jpg
                lazy.jpg
    
          hakemisto_b
                etherkill.jpg
    
          jap-inv3.jpg
          tekstia.txt
  8. With the ZIP file:

  9. Compile this C source code with gcc and check if it works. helloworld.c source code:

    #include <stdio.h>
    
    int main(void) {
        printf("Hello, world!\n");
        return 0;
    }
  10. Compile this C++ source code with g++ and test it. helloworld.cpp source code:

    #include <iostream>
    
    using namespace std;
    int main()
    {
         cout << "Hello World!\n";
    }
  11. With previously compiled helloworld C++ binary:

  12. Solve these service management assignments (Note: most assignments will require root access):

  13. Test these service management commands with your web server and use web browser to verify the operation whether the server is running or not:

    Somewhat bad or at least old way of some or older distros:
    
    service apache2 stop
    service apache2 start
    service apache2 restart
  14. Test these service management commands with your web server and use web browser to verify the operation whether the server is running or not:

    Generic System V style, also old school:
    
    /etc/init.d/apache2 stop
    /etc/init.d/apache2 start
    /etc/init.d/apache2 restart
  15. Test these service management commands with your web server and use web browser to verify the operation whether the server is running or not. Try and explain:

    Modern way for distros using systemd:
    
    journalctl | tail -20
    systemctl restart apache2
    journalctl | tail -20
    systemctl stop apache2
    systemctl start apache2
    systemctl
  16. Check Apache access.log file contents in /var/log/apache2/ directory. Can you find your connections to the web server?



Course week 3

Assignments to the learning diary (You can do these in small groups. Learning diaries are personal):

  1. Study and explain shortly following commands and concepts:

  2. How and when you start new shells? How to exit a shell?

  3. Add shell alias “diskusage” to your shell startup-files (example .bashrc). Alias should print only current disk usage of your home directory

  4. Create shell alias “pp” which requires one parameter and will print all running processes including details with that name. Usage example:

    tkorpela$ pp sleep
    root 21109  0.0  0.1  4084  556 pts/8  S  20:02   0:00 sleep 100
    root 21111  0.0  0.1  4084  556 pts/8  S  20:03   0:00 sleep 100
    root 21113  0.0  0.1  3684  556 pts/8  S  20:03   0:00 grep sleep
  5. Which directories are currently in you PATH variable?

  6. How do you start process directly into background when entering a command?

  7. Start few sleep 60 processes (one minute idle loop) to the background and:

  8. What is the difference between kill -9 and kill -1?

  9. Delete unnecessary files created in this practice.

Extra assignments (No need to answer to the learning diary. Ignore for grading):



Course week 4

Assignments to the learning diary (You can do these in small groups. Learning diaries are personal):

  1. Study and explain shortly following commands and concepts:

  2. Use word counter and piping to count how many files or directories are in /usr/bin -directory?

  3. Use grep and extended regular expression syntax to list all files from /etc directory recursively which have IPv4 addresses mentioned inside

  4. Download and extract Tetris game source file nct-1.4.tar.gz and

      2139 configure
      943 nct.c
      392 Makefile.in
      340 COPYING
      251 install-sh
      195 score.c
      190 missing
      182 INSTALL
      127 aclocal.m4
      48 README
      44 config.h.in
      43 Makefile.am
      43 configure.in
      42 score.h
      40 mkinstalldirs
      38 nct.spec
      22 NEWS
      21 nct.h
      17 nct.lsm
      3 ChangeLog
      2 acconfig.h
      1 stamp-h.in
  5. Use wget to download this irclog.txt and answers to these questions:

     44 ryan_
     40 ryan||
     34 ryann
     15 AlexC_
     12 scottymeuk
     12 Ruchira
     11 ryannn
     11 kyhwana
     11 gerryvdm_mbp
     10 shmoon
      7 chesty
      6 Ruchira_
      3 ssthormess
      2 rww
      2 mestri
      2 drclawski
      1 ryan|
      1 mikegrb
      1 gkmngrgn
      1 akerl
  6. List only 5 largest files from /usr/bin -directory.

  7. Print only usernames, UID and GID numbers from /etc/passwd -file. Replace all colons with a whitespace. Redirect output to file a “users.txt” in your home directory. Tip: In this example line from /etc/passwd the UID = 101 and GID = 50:

    username:x:101:50:Teemu Korpela:/home/tkorpela:/bin/bash
  8. Use text editor nano to create a points.txt file to your home directory with following content. This list presents first names and some game scores. Who has most points, wins

    points.txt file:

    Teemu:4
    Matti:8
    Juha-Pekka:6
    Timo:1
    Mika:3
    Esko:2
    Jaska:5
    Erkki:7
  9. How do you list last 5 lines from the /etc/passwd file?

  10. How do you list first 5 lines from the /etc/passwd file?

  11. What does tail -f filename command do?

  12. Fetch current weather in Oulu with lynx (TIP: if there is no lynx, install it with: sudo apt install lynx). The command to download Oulu's weather data is: lynx -dump http://weather.willab.fi/weather.html

  13. Use wget to download this stock market textfile

    Example line and explanation from file:

    Name                  code   change buy  sell lowest highest last
    Fiskars  Corporation :FISAS: -0,36% 8,35 8,39  8,44   8,37   8,37

    Output should be:

    Metso  Corporation :MEO1V: -0,08% 11,77 11,79 11,80 11,73 11,79
    M-real  Corporation  A :MRLAV: -0,42% 4,64 4,83 4,75 4,75 4,75
    M-real Corporation B :MRLBV: -1,06% 4,65 4,67 4,75 4,64 4,67

    Output should be:

    Rautaruukki  Corporation :RTRKS: +0,24% 8,46 8,50 8,52 8,42
    Rocla Oyj :ROC1V: -0,60% 8,20 8,25 8,25 8,20 8,25
  14. Get nimipaivat.txt (Finnish name days) textfile from here nimipaivat.txt

  15. Use lynx -dump “url” to print webpage to STDOUT

  16. HTTP access to XML:

    curl -s -L http://weather.willab.fi/weather.xml |  _replace_with_your_commands_options_and_code_
    12.3
  17. Combine these two files to a single file with command line Gnu text tools

    ...
    Sat Apr 11 11:03:42 2020:185.176.27.26
    Sat Apr 11 11:03:43 2020:188.26.0.66
    Sat Apr 11 11:04:15 2020:185.176.27.34
    Sat Apr 11 11:04:57 2020:87.251.74.250
    Sat Apr 11 11:05:00 2020:94.102.52.57
    ...  
  18. Delete unnecessary files created in this practice



Course week 5

Assignments to the learning diary (You can do these in small groups. Learning diaries are personal):

  1. Study this Telegram bot game version 0.1, this improved version 0.2 and even more improved version 0.3

    Output should look like this (that 11 is the word length):

    $ ./telegram_wordgame_v3.bash 11
    01 _____M_____
    02 ___O_M_____
    03 ___ORM_____
    04 A__ORM_____
    05 A__ORM__I__
    06 A__ORM__I_Y
    07 A__ORM_LI_Y
    08 A_NORM_LI_Y
    09 A_NORM_LITY
    10 ABNORM_LITY
    11 ABNORMALITY
  2. Study and try this simple incremental / full backup example script. Do automatic backups as a root user:

  3. Create a file size comparison Bash script:

    Example output:

    $ comparemyfiles
    Enter name of first file:
    something
    
    Enter name of second file:
    thisfiletoo
    
    File something is larger.
  4. Change previous script to accept two filenames as a command line parameters. Example output should be something like this:

    $ comparemyfiles something thisfiletoo
    File something is larger.
  5. Think why second solution (to use parameters after the command instead of interactive input) is usually more practical solution?

  6. Create “Rock Scissor Paper”-game with Bash

    echo $[RANDOM%10]

    More advanced PRNG using /dev/urandom:

    echo $[$(od -vAn -N2 -tu4 < /dev/urandom)%10]

    Or with shuf:

    shuf -i 1-10000 -n 1
  7. Create a welcoming script which will check current time and will echo welcome message if time is:

    06:xx-11:59 = Good morning user's_realname_from_/etc/passwd-file
    12:xx-17:xx = Good day user's_realname_from_/etc/passwd-file
    18:xx-21:xx = Good evening user's_realname_from_/etc/passwd-file
    22:xx-05:xx = Good night user's_realname_from_/etc/passwd-file

    Example output (time 12:43):

    $ welcomescript.bash
    Good day Teemu Korpela
  8. Create a script which will check current date and searches all persons having finnish name day at the moment. You can use nimipaivat.txt as a datafile

    Example output:

    $ date
    Mon Dec  2 17:42:21 EET 2021
    
    $ ./nameday.bash
    Anelma 2.12.
    Unelma 2.12.
  9. Install SQLite3 database engine and tools to the Linux server (basic tutorial here) and:

    Example output:

    ./fetch_random_name.bash
    Liisa
    ./fetch_random_name.bash
    Tiina

Extra assignments (No need to answer to the learning diary. Ignore for grading):



Course week 6

Assignments to the learning diary (You can do these in small groups. Learning diaries are personal):

  1. Install Apache web server to your Linux server if it isn’t installed already

    <?php
    date_default_timezone_set('UTC');
    echo date("l");
    echo ("<br>");
    echo date('l jS \of F Y h:i:s A');
    echo ("<br>");
    echo date(DATE_RFC2822);
    ?>
  2. Modify the Apache web server configuration to redirect HTTP GET requests to the directory /weather/ to https://wttr.in/. You will most likely need to enable the redirect module for Apache

  3. Check last entries in Apache access and error log files in /var/log/apache2/

  4. Install MySQL server and create some basic database there with one or more tables and insert some data into the table(s). See the basic MySQL example with PHP

    $ sudo mysql
  5. Create a Bash script which will fetch and process data from marine traffic API

    curl --compressed -L https://meri.digitraffic.fi/api/v1/port-calls -o /tmp/result.json
  6. Create a Bash script which checks spaceX launch schedule API and tells how many days ago was the last launch. Result should be something like this:

    ubuntu@linux100:/tmp$ ./whenwasthelaunch.bash
    4 days ago
  7. Create this Bash script to /usr/local/bin directory. Name it to justtimestamps.bash and set the file permissions to 700 (root user has full access, others none). Check that the root is the file owner:

    #!/bin/bash
    
    while true; do # this is endless loop
        date >> /root/timestamps.txt # writing timestamp to a file
        sleep 60 # 60 second delay
    done
    [Unit]
    Description=My automatic service writing timestamps to a file in /tmp
    After=network.target
    
    [Service]
    Type=simple
    User=root
    Group=root
    ExecStart=/usr/local/bin/justtimestamps.bash
    WorkingDirectory=/tmp
    Restart=on-failure
    
    [Install]
    WantedBy=multi-user.target

Extra assignments (No need to answer to the learning diary. Ignore for grading):



Course week 7

Assignments to the learning diary (You can do these in small groups. Learning diaries are personal):

  1. What is a Linux container? (with any technology such as LXC/LXD, Docker, Podman). Generic description what is a Linux container is enough.
  2. What is the difference between chroot, containers and full operating system virtualization (like Virtualbox, VMware, Hyper-V etc.)?
  3. What is Kubernetes?
  4. What is Ansible?
  5. What is Terraform?
  6. Install Docker engine (docker.io) package to your server from standard package repository or from the Docker official repository
    docker run --rm -d -v /opt/docker/searx/searx:/etc/searx -p 44444:8080 -e BASE_URL=http://localhost:44444/ searx/searx
  7. Browse these container building tutorials: Create a Docker image running Robot Framework and Docker Build: A Beginner’s Guide to Building Docker Images
  8. Install Ansible to the Linux server and to your workstation (or some another Linux workstation/server) and:
  9. Explain shortly what is Robot Framework

Extra assignments (No need to answer to the learning diary. Ignore for grading):



Course week 8

Topics:



This page was modified: 2023-02-05