Linux assignment 7

H7

Assignment given by Tero Karvinen

a) Ratkaise valitsemasi vanha arvioitava laboratorioharjoitus tältä kurssilta. (Löytyy DuckDuckGolla tai Googlella sekä linkeistä tältä sivulta).

b) Kaikki tehtävät arvioitavaksi. Palauta linkki sivuun, josta löytyvät kaikki kotitehtäväraporttisi. Arviointi tehdään ensisijaisesti tästä linkistä. Linkki voi olla esimerkiksi blogin etusivu (jos blogissa on vain kotitehtävät) tai sivuun, jossa on linkki kuhunkin tehtävään. Kaikki tehtävät -linkin palautus Moodlessa kohtaan “Kaikki tehtävät arvioitavaksi”.

c) (vapaaehtoinen) Käytä Linuxia kurssin ulkopuolella.

d) (vapaaehtoinen) Varaa kalenteristasi viikon välein aikoja Linux-harjoitteluun kurssin jälkeen.


Testing environment

I did this assignment using Asus R517S and live USB-stick with Ubuntu 16.04


Exam

a) In this assignment I had to do one old exam. So i went ahead and chose on from the assignment page. This was the exam I chose. Why I chose this was because it was the newest.

1. Haluamme tehdä PHP-kotisivuja etäältä

1.First thing I had to do is to do a PHP homepage from afar.

So to start this task I installed Apache, PHP and SSH:

$ sudo apt-get -y install apache2 libapache2-mod-php ssh

Then I logged to SSH a:

$ ssh ubuntu@localhost

And then I had to do a PHP homepage.

First I had to allow users homepages and php:

$ sudo a2enmod userdir

$ sudoedit /etc/apache2/mods-available/php7.0.conf -> this is where I had to comment out the if-statement

$ sudo service apache2 restart

Now I had to test the PHP-homepage:

$ mkdir public_html

$ cd public_html/

$ nano index.php

Then I opened localhost/~ubuntu (ubuntu is your username, I had ubuntu because I had live USB-stick):

php apache page

And it worked. So I managed to install PHP, Apache and SSH. Log into my SSH and made and PHP-homepage that is working!


2. Työntekijöitämme ovat Jorma Mähkylä, Pekka Hurme, Ronaldo Smith, Håkan Petersson, Einari Mikkonen, Einari Vähäkäähkä, Eija Vähäkäähkä. Tee heille HTML5-esimerkkikotisivut siten, että kunkin testisivun otsikossa lukee omistajan käyttäjätunnus.

2. So second task I had to made HTML-homepages for employees and the title of the pages had to be the username of employees.

So I needed to create many user and make for every user a homepage which had a title of that users own username. I could start making user and individually make a new homepage for everyone. But there is a faster way. Faster way is to add any file or folder to /etc/skel directory and when I would create a new user, they will have those files.

$ cd /etc/skel/

$ mkdir public_html

$ sudo mkdir public_html

$ cd public_html/

$ sudo nano index.html

Now I could start making new users. For passwords I used application pwgen which I simply installed with:

$ sudo apt-get install pwgen

I created a password.txt where I would keep all the password, but I dont want anyone to see it but me. So I had to change permission of the file so only I could read and write:

$ chmod og-rwx password.txt

and with ls -l password.txt I could check the permissions on the file:

Selection_001

Now only user ubuntu can write and read the file.

So with the command:

$ sudo adduser ‘username’

I started adding users.

With comman:

$ cat /etc/passwd

I could see all the users in the end of the file:

Selection_002

Then I tested users by logging to them via SSH by entering ssh jormam@localhost. I had given every user a password so I entered the password and succesfully logged in. I also checked just in case that user jormam had the public_html file. He had the file.

Now I just had to change the index.html file for title to show everyones username.

The title is everyones username and url is also different for everyone localhost/~”username”/. So I can say I did this part!

ronaldos


3. Maija Virtanen jatkaa ylläpitoa, tee hänelle sudo-tunnus. Maija haluaa käyttäjätunnuksen “maija”.

3. Now one Maija Virtanen wants to have sudo privileges and username to be ‘maija’.

Firstly I create user maija and then I added maija to sudo group:

$ sudo adduser maija

$ sudo adduser maija sudo
Adding user `maija’ to group `sudo’ …
Adding user maija to group sudo
Done.

I checked that I had user maija again with:

$ cat /etc/passwd

Selection_003

Maija was now also had a user!


4. Jorma aikoo kehittää uuden sivun sleep.example.com. Laita Jorman kotisvu näkymään myös tästä osoitteesta. Voit simuloida nimipalvelun toimintaa hosts-tiedoston avulla.

4. Jorma plans to develop a new page sleep.example.com. Put Jorma’s home page on this address as well. You can simulate a name service by using a hosts file.

Help i got to this task.

Because I already did Apache and tested it so I dont need to install it again. I also had Jorma’s own homepage so I just needed it to show on sleep.example.com address. I navigated to /etc/apache2/sites-available/:

$ cd /etc/apache2/sites-available/

And created a new config file:

$ sudoedit sleep.example.com.conf

And added the following text and saved it the file:

Selection_004

I had error in this file and the error was that I did close . Error I checked with apachectl configtest. So I corrected it:

Selection_005

Then I had to enable the conf file and restart the Apache daemon:

$ sudo a2ensite sleep.example.com.conf

$sudo service apache2 restart

After this I had to edit hosts file with sudo permission:

$ sudoedit /etc/hosts

And added the following lines:

Selection_006

Then I navigated to the site to test that it was working. I used Firefox to test this Selection_007

It was working and everyones elses page was working fine!


5. Suojaa kone tulimuurilla.

5. Protect the machine with a firewall.

So this was a quick task. Firstly I had to make a hole to firewall for using SSH later on and the enabled the firewall:

$ sudo ufw allow 22/tcp
Rules updated
Rules updated (v6)

$ sudo ufw enable
Firewall is active and enabled on system startup

Firewall was on!


6. Tee Pythonilla uusi komento ‘wowstats’, joka tulostaa käyttäjälle tervehdyksen. Sen tulee toimia jokaisella käyttäjällä työhakemistosta riippumatta.

6. Make Python a new command ‘wowstats’ that prints a greeting to the user. It should work for every user irrespective of the job directory.

Because I had to make a Python command so I had to check that I had the newest python3 installed. Usually it is preinstalled on Ubuntu but it is good to check!

$ python –version
Python 2.7.12

I had the newest so I continued with the task. So I started by creating a file named wowstat.py. Then for to make it available for all users I had to move to /usr/local/bin/ and then it was available to all users:

$ nano wowstat.py

$ chmod a+x wowstat.py

$ sudo cp wowstat.py /usr/local/bin/

And tested that it was working and all user by logging in with SSH to one of the user and type wowstat.py. It printed the text so I did the task!

Selection_008

The text inside wowstat.py file is this:

Selection_009


6. Linuxilla voi kuulemma tehdä metapaketteja, eli paketteja, jotka asentavat toisia ohjelmia – vieläpä uusimpina versioina ja kaikkine päivityksineen. Haluamme itsellemme metapaketin nimeltä kurssikuru-coding, joka asentaa suosikkityökalumme git, ipython3, meld, gedit. Tee tällainen metapaketti ja asenna se. Katso vinkkejä Googlesta “karvinen equivs”. Liitä metapaketin lähdekoodi (ilman kommenttirivejä) lab.txt:n perään. Paketin nimen pitää olla “kurssikuru-coding”.

6. Linux can be made to make meta packages, that is, packages that install other programs – even with the latest versions and with all the upgrades. We want a metapaket called kurssikuru-coding, which installs our favorite tool git, ipython3, Meld, gedit. Make this kind of metapack and install it. See tips on Google “Karvinen equivs”. Paste the metapaket source code (without comment lines) after lab.txt. The package name must be “kurssikuru-coding”.

Instruction for this task I used this!

To start this task I had to install eqivs:

$ sudo apt-get -y install equivs

Then I had to create source file name kurssikuru-coding:

$ equivs-control kurssikuru-coding.cfg

Then I had to change “Package”, “Version” and “Depends” and removing “#” from lines that I am using.

$ nano kurssikuru-coding.cfg

Then I had to add packages I want to install. Packages have to work with “sudo apt-get install” command.

This is what I did for this task:

Selection_010

Then I had to build the package:

$ equivs-build kurssikuru-coding.cfg

And finally I had to test it. And before testing I had to install gdebi:

$ sudo apt-get -y install gdebi

After installation I could like check every program that I installed but as I didnt get errors there are installed. but for example –version I could check versions.

About
This document can be copied and edited according to the GNU General Public License (version 3 or newer). http://www.gnu.org/licenses/gpl.html

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s