Tag Archives: ubuntu

SALT: CHANGE XUBUNTU DEFAULT BACKGROUND WITH SALTSTACK

In Xubuntu and Ubuntu changing the default background is relatively simple. All you need to do is locate the default background file (a binary file) and replace it with the wanted background.

In Xubuntu 14.04, the file is located in
/usr/share/xfce4/backdrops/
And goes by the name of xubuntu-wallpaper.png

In Salt, the easiest way to replace the default background is simply to override it with a state.

First, create a sls. -file for the state. I called mine background/ init.sls. Next you will want to dump your new background into the module folder.

Selection_003

The init.sls -file’s contents are the following:
(I used #!pyobjects to override the file)

#!pyobjects

File.managed("/usr/share/xfce4/backdrops/xubuntu-wallpaper.png", source="salt://background/img.png")

This piece of code will override the default wallpaper. After relogging the background should be updated to your chosen wallpaper.

Running the state:

Selection_004

  • Copying, modifying and redistributing this and all the other documents in this blog is allowed according to the GNU General Public License (versio 2 or newer).http://www.gnu.org/licenses/gpl.html
  • Based on the Linux course by Tero Karvinen 2015: terokarvinen.com
Advertisements

SAMBA SERVER SETUP IN VIRTUAL NETWORK || ASSIGNMENT

The platform for this assignment varies a little. It was started at the campus using a comp with these specs, and carried on with my home PC.
The virtual environment, i.e. the virtual machines were exported and imported to a USB-stick, which allowed the handy usage of the virtual machine(s).

THE ASSIGNMENT:

  • Install a new machine, running Ubuntu Server, to the virtual environment. Install the Samba server and the SSH-server to this machine.
  • Install a new machine, running Windows 7, to the virtual environment.
    (unfortunately I was unable to transfer the Windows machine within the USB-stick, the time it took to export this machine was measured in hours, and I really did not have the time or the patience to wait for this.)
  • Using the Ubuntu Server Guide and the Samba-HOWTO-collection, test and configure the Samba server. Do not setup a printing server, only the file server.
  • Setup disk quotas for the users, i.e. give them Samba -server accounts.

Step 1. Installing the new machine

Firstly, I installed the new Ubuntu Server machine. During installation I selected the Samba server and Open-SSH server to be included in the installation. After the installation was completed I proceeded in configuring the Samba server.

I also installed a new Linux desktop to the environment, running Kubuntu 14.04 LTS, to kind of replace the Windows desktop.

Step 2. Configuring the Samba server

Telling Samba what to do is rather simple. The configurations will change during the setup progress, since I’m proceeding in a step by step manner.

First we need to edit some key/value pairs in the Samba-configuration file. It can be accessed using this command:

sudo nano /etc/samba/smb.conf

Here we will want to look into the [global] -section first. We will need to give our workgroup a name, and give a basic security declaration. My conf-file’s [global] looks like this: globalconf

Next I created a new section to the bottom of the conf-file called “[share]”. This section will define the sharing policies of the file server. You might want to add these lines to it:

[share]
comment = Samba File Server #just a friendly reminder
path = /srv/samba/share #we will create this later
browsable = yes
guest only = yes
read only = no
create mask = 0755

My section looks similar to the one above:
sambashare

Now Samba is configured.

We will now need to create the shared directory, so run these command:

sudo mkdir -p /srv/samba/share
sudo chown exmpl.nogrp /srv/samba/share/

Samba needs to be restarted in order for the configurations to apply:

sudo restart smbd
sudo restart nmbd

You can also run a command “testparm” to check if the configuration file syntax is correct.

testparm

There you go. Local network configuration is done!
Your machines in your local network should now detect the Samba file server.

Step 2. Detecting the server

This really isn’t a step at all. Just log into one of your desktops, also connected to the internal network and go check the “Network” (if debian) folder.
kubuntu1
In my Kubuntu, I could find the “Samba Shares” folder without any further configurations. Clicked it and:
kubuntu2
I can find a few shared networks here, since other people were doing the same stuff in the same network. I could find my network “Example.lan” on the top.
kubuntu3
Two folders here, “data” and “share”. We just created the “share” folder. And I also made a text-file there on the server machine, for testing purposes.
kubuntu4
Looks like it works!

If you have problems accessing the folders, you might not have permission to them. Try checking the [share] settings. If that doesn’t work, try using chmod to see if the problem is there.

sudo chmod -c -rwxrwxrwx /share

This of course is not very good considering data security, but we just want to see if this is the problem.

Step 3. Users

Users need both accounts on the server and accounts in Samba. So create the users into your server machine. After that let’s make them in Samba as well.

Users are already created in the server, they are valid Samba users. So we only need to give them Samba specific passwords. That is done with the command:

sudo smbpasswd -a user

This how it will look in the terminal:
sambaa
As we can see here, Samba really doesn’t appreciate my security settings. I also ran into this while checking the Samba status with:

smbstatus

Now this is how it looked. (the server is not working properly yet, we’re on it)
smbstatuserrro

I brute forced this error out, no one likes error:
sharefixstatus
Messy work around, but it does the job for now. The status looks much better now too:
fixederror

Let’s see if we can log into our Samba server.
Root login:
lookmomidiit

sudo smbclient //172.28.9.225/share

If you want to log in with a account is is done with this command:

smbclient //172.28.9.225/share U-usrname/pw

artopäässisää

Server status

We can check the server status using this command:

smbclient -l samba -u%

sambastatus-u

Looks alright.

The users have now been created and the server configured. The next step is to mess around with disk quotas.

Step 4. Disk quotas

Let’s set up disk quotas for our users.  Install the software using this command:

sudo apt-get install quota

After installation take a copy of the conf -file located: /etc/fstab. After open the conf -file.

sudo nano /etc/fstab

By default the file looks as follows:
quotadefautl
Add ,usrquota after the errors=remount,ro -part. Don’t remove anything. This file is extremely picky with the syntax.
The modified file will look something like this:
quotamod

Run a remount to apply the settings:

sudo mount -o remount /

Now, be sure to have your quota turned off before running the check commands. Execute the commands as follows:

sudo quotaoff /
sudo quotacheck -cum /
sudo quotaon /

Now we can set quotas for our users using the sudo edquota

sudo edquota juhotest

edquota
We can set the usable disk space etc here. Like this:
edquotareals

After we’ve set quotas as wanted we can see if they are applying. Checking for user quotas can be done with the command:

quota userhere

quotacheck

And there we have it!

DHCP & DNS // CREATING A LOCAL NETWORK BETWEEN VIRTUAL MACHINES // ASSIGNMENT III

So, my external hard drive is a brick. To summarise the problem; It just won’t boot. So I am will run this assignment on a Windows desktop, since my laptop is not strong enough to run so many virtual machines at once.

Specs:
Windows 7 Enterprise 64-bit
Intel Core i5-2400 @ 3.10GHz
Some integrated Intel HD graphics GPU
8GB of RAM

Assignment:

Create four virtual machines:

## Machine A: Linux desktop, I’ll be using Mint 17. This machine will receive its network address from the DHCP -server.  Eth0 in the local network (intnet). ## Machine A not used in this post

Machine B: Master, running Ubuntu server. This machine will work as a DHCP – server. Static IP, Eth0 in local network.

Machine C: Bridge, running Ubuntu server. This machine works as a NAT -distributor (If it works..) between the local and public network. Static IP, Eth0 in public network (bridged), Eth1 in local network (intnet).

Machine D: Running Ubuntu server. Receives IP from the DHCP -server. Address reserved before hand using MAC -address. Eth0 in local network. Calling this machine ‘Aku’ on this post.

Step 1.

Creating and installing the virtual machines will be the first step. I begun with installing all the machines using Ubuntu server. I gave them all 512 MB of RAM and 8 GB of space on the hard drive, the desktop client gets a bit more RAM etc, but servers will manage with less.

During the installation, I also installed the OpenSSH -client. Machine B also got the DNS-server package during installation.

Bridged network setting is necessary here, since we still need to access public network, in order to make a few installations here.

Machine C – the bridge, will need two network adapters here. It will work as a gateway to the public network for the other machines. Set Eth0 to public network setting – Bridged, and Eth0 to internal network. Primary network adapter = Eth0.

After setting up Machine C – the bridge, run this command:
ls /sys/class/net/
This should list you the following adapters: eth0, eth1 and lo.

Step 1.2 DHCP-server installation

After the machines are setup, installing the DHCP -server on the master machine is necessary. It can be done with the following command:

sudo apt-get install isc-dhcp-server

Be sure to have bind9 installed before doing this. (sudo apt-get install bind9)

This will install and start the DHCP -server. However, it still needs go through the process of configuration.

After the installation is completed, everything that needs to be installed on this machine has been installed. Now we can change the IP to a static IP.

sudo nano /etc/networks/interfaces

This will open up the configuration file in which you can tweak your IP setting. It will look a bit like this:
Selection_001
You will need to change a few lines in order to make your IP static. Add these changes into the file:

auto eth0
iface eth0 inet static
address 10.5.5.1
netmask 255.255.255.0
network 10.5.5.0
broadcast 10.5.5.255
#dns-nameservers 10.5.5.1

For now, leave the dns-nameservers commented out.
masterinterfaceconf

Save the file and run these commands:

sudo ifdown eth0
sudo ifup eth0

This will apply the changes made and give you a new IP. Now if you run ifconfig your IP should display as 10.5.5.1 – you now have a static IP.

Configuring the /etc/hosts -file might not be necesary, but I’d say do it just to be sure. Capture
We will want to change the IP here to our own static IP and fill in the host’s name – master.

Step 1.2 Gateway//Bridge

Before testing, make sure all your other machines have also got the appropriate IP settings in /etc/network/interfaces:
Capture2
On the bridge machine, we will want to leave the eth0 -setting untouched and make a similar configuration for the eth1 -adapter.
Eth1 – adapter is in the internal network, so we will want to give it static IP and other configurations as seen above.

Remember, for the settings to apply, you will need to run ifdown and ifup -commands.

Step 2. Testing the work done so far

At this point we can test if that the machines can find each other using SSH.
We can start by trying to connect from MASTER —> BRIDGE

ssh juho@10.5.5.2

You should get similar results:
sshtest

Step 3. Configuring the DHCP -Server

Configuration here is done in a similar way to the prior part of the assignment. You will need to access the .conf file and tweak it a bit.

sudo nano /etc/dhcp/dhcpd.conf

This is how it will look by default:
Selection_003

You will need to add these lines into the .conf -file:

subnet 10.5.5.0 netmask 255.255.255.0 {
range 10.5.5.10 10.5.5.30;
option domain-name-servers 10.5.5.1, 8.8.8.8; 
## 8.8.8.8 is google's name server, which work as a backup here
option domain-name "yournetwork'snamehere.example";
option broadcast-address 10.5.5.255;
#option routers 10.5.5.1 #if you need this 
}

After adding this to the file, it should look a bit like this:
dhcp3

Depending on how you want to build your network, you might want to set fixed addresses to your machines. This is done using MAC-addresses and the configuration is done to the same file we’re in now. Here’s how you’ll do it.

 host hostname {
      hardware ethernet 08:00:27:ff:03:57; 
      fixed-address 10.5.5.40;
      } #remember to close the script

“hardware ethernet” is the mac-address of the machine whose IP you want to set as fixed. It can be found in ifconfig.
“fixed-address” is the IP you want to set. Preferably set it outside the range set above, to avoid overlaps.

My conf-file looks like this:
dhcp4
I gave all my machines fixed-addresses.

Now we need to restart the DHCP -server. It is done with this command:

sudo /etc/init.d/isc-dhcp-server restart

You should get similar results:
Selection_005
Now the DHCP -server has been configured.

Now the other machines should receive a fixed address, if their network is set to internal. Let’s test this. Machine D, aka Aku, let’s refresh the connection with ifdown and up, and see what kind of IP will we get. It’s supposed to be 10.5.5.40.
akutest
Looks like it worked!  We can also see from the messages on the terminal, that the DHCP-server is working properly.

Next step is to configure the server so, that the machines in internal network can also access public network. That will be done in the next post.

BACK2SCHOOL BACK2LINUX // RUNNING UBUNTU SERVER ON A VIRTUAL BOX ON UBUNTU // ASSINGMENT 1

I’ve had a quite a break on this blog and Linux-stuff in general. Here’s the first assignment of the “Linux as a Server” -course I’m taking this semester. Also decided on posting in English this time.

The workstation’s specs here.
sudo lshw -html > specs.html

Today’s assignment was the following;
-Run Ubuntu Server on Virtualbox. Install Apache so that a website can be created in the default folder.
-Change the current folders owner and group and also user rights following the steps provided
-Create users Tupu, Hupu, Lupu and Aku.
-Create a user group called “kehittajat” and include Tupu, Hupu and Lupu in it
-Grant Aku sudo rights
-Grant Tupu access into www-data -group

Step 1.

I installed Ubuntu 14.04.1 LTS in to the current workstation, and ran a few necessary commands;
sudo apt-get update
sudo apt-get upgrade

After this I installed Virtualbox
Selection_005
After installation it will boot up simply by this command
Selection_006

 

Step 2.

Next step is to install Ubuntu Server on Virtualbox.
I downloaded Ubuntu Server from here.

I created a new virtual machine using all default setting, except I did boost the memory up to 1.5gb. Otherwise every setting is as it was. Here you can see the overview of the virtual machine:
ubuntu

I installed Ubuntu Server using default settings as well. Since I’m only doing this locally, there was no need to setup proxies or any fancy stuff like that.

Selection_008

The completed installation looks like this:

server

 

Step 3 –  managing group setting / adding users

Next step is to change the directory’s owner and group as well as the user rights. It is done with these commands:
(you need to be located in /var/www)

sudo usermod -a -G www-data juho
sudo chgrp -R www-data /var/www
sudo chmod -R g+w /var/www

Creating the needed users:
users

Creating the user group:

createnewgroup

Granting the users rights into the new group:

kehittajat

Step 4 – Granting rights to users

Granting Tupu the rights into www-data

tupuwww

Giving Aku sudopowes:

akunoikeudet

 

Step 4 – Setting up Apache

Installing Apache web server is done with the following command:
       sudo apt-get install apache2

html

koodi

 – Assignment completed. Users are now assigned to their groups and granted the rights they  should have. The web server is also set up

Problems occurred: 

No significant problems occurred during the assignment, the assignment itself was relatively simple.

However, playing around with Virtualbox, me and many of my colleagues noticed a problem with running Ubuntu LTS 14.04.1 with Virtualbox. The problem was, that the screen size/resolution didn’t scale properly with the Virtualbox client. Easy fixes to this can be found online, but I decided to solve this in a different way: using a different distribution.

Linux Mint 17 runs perfectly with Virtualbox, and offers everything that Ubuntu has to offer as well. Mint uses the same repository for as Ubuntu – aptitude as well, so  there are no problems in this regard.

 

 

 

Kotitehtävä VII: “Hei maailma”

Tehtävänanto:

Käännä “hei maailma” kolmella kielellä, jota ei käsitelty tunnila.

Tietokoneen kokoonpano ja työympäristö:

  • Malli: Fujitsu Lifebook AH532
  • Suoritin: Intel Core i3-2328M 2.2GHz
  • Näytönohjain: Intel HD Graphics 3000
  • Muisti: 4Gb DDR3
  • Käyttöjärjestelmä: Ubuntu 12.04 LTS 64-bit

Java:

Javaa varten minulla on jo asennettuna koneelle Eclipse-kehitysympäristö.

javasanoomoi

Javalla “Hei maailman” teko onnistuu helposti.
Eclipse antaa (valittaessa) määrittäjät public static void main(String[] args) itsestään, ja itse koodi on vain rivin pituinen.

System.out.println() tulostaa annetun tekstin.

Tässä vielä hieman edistyneempi Java-ohjelma, jonka olen joskus vääntänyt. Ohjelma laskee neliön pinta-alan.

javallasama

Ruby

Rubyllä “Hei maailman” tekeminen onnistuu näin:

rubymoi
Tämän jälkeen, kun avaa tiedoston Rubyllä, eli ruby “tiestostonnimi”
Printtaa Ruby kyseisen tekstin.

C/C++

Eclipse näköjään tukee myös C:tä ja C++:saa. Asentelin Eclipseen tarvittavat paketit komennoll :

sudo apt-get install eclipse-cdt
sudo apt-get install g++

Sitten vain kirjoiteltiin koodi IDE:en.
c++moi

 

Kotitehtävä V: SQL

Tehtävänanto:

  • Asenna tietokantapalvelin ja kokeile SQL:ää komentokehotteesta. Luo uusi mysql-käyttäjä. Tee taulu, syötä siihen tietoa ja hae sitä. Voit halutessasi aloittaa tyhjästä liverompula.

Tietokoneen kokoonpano ja työympäristö:

  • Malli: Fujitsu Lifebook AH532
  • Suoritin: Intel Core i3-2328M 2.2GHz
  • Näytönohjain: Intel HD Graphics 3000
  • Muisti: 4Gb DDR3
  • Käyttöjärjestelmä: Ubuntu 12.04 LTS 64-bit

Tietokantapalvelimen asennus:

MySQL-tietokantapalvelimen asennus on erittäin helppoa. Se onnistuu komennolla:

“sudo apt-get install mysql-server

Asennusprosessin aikana, asennusohjelma pyysi minun antavan MySQL:lle root-salasanan, eli pääkäyttäjän salasanan.

Käyttäjän luonti:

Ensiksi avasin itse MySQL:n. Tein tämä MySQL:n pääkäyttäjän oikeuksin komennolla:

mysql -u root -p

Tämän jälkeen, MySQL pyysi pääkäyttäjän salasanaa, jonka annoin.

mysql
Ja tältä se sitten näytti.

Komennolla: SHOW DATABASES;  – MySQL luettelee kaikki jo järjestelmässä olevat tietokannat.
Tietokannan valinna jälkeen ohjelma ilmoittaa “Database changed.”

Teen uuden tietokannan itselleni. Se tapahtuu seuraavasti:

Ensiksi teen itse tietokannan.  Se onnistuu komennolla CREATE DATABASE nimi;
Nimeksi annan tietokannalleni vaikka ‘testitietokanta’.

Seuraavaksi annan itselleni oikeudet tietokantaan, ettei minun aina tarvitse käyttää sitä pääkäyttäjänä. Se tapahtuu komennolla:

GRANT ALL PRIVILEGES ON testitietokanta.* TO juho@localhost IDENTIFIED BY ‘salasana’;

Nyt voin kirjautua itsenäni sisään käyttämällä komentokehotteessa komentoa:

mysql -u juho -p testitietokanta;

Nyt kun kirjoitan SHOW DATABASES; – tulisi minun nähdä oma tietokantani.

testitietokanta
Ja siellähän se on!

Taulun tekeminen ja tiedon tallentaminen

Nyt voimme tehdä tietokantaan taulun!

Tein taulun tietokantaan, johon voidaan tallentaa asiakkaan nimi ja puhelinnumero komennolla:

USE testitietokanta;
CREATE TABLE test( nimi VARCHAR(50) , puh VARCHAR(10))

Ohjelma vastaa: Query OK, 0 rows affected (0.57 sec)

Tallensin tauluun ‘testi’ tietoa komennolla:

INSERT INTO test VALUES(‘JASKA’ , ‘1234567890’);

Nyt kun haluan etsiä tietoa tietokannastani ‘test’ teen sen komennolla:

SELECT * FROM test;
tai jos haluan etsiä pelkästään nimeä ‘Jaska’
SELECT ‘Jaska’ FROM test;
jne.

 

Kotitehtävä: PHP

Tehtävänanto:

  • a) Tee käyttäjän kotisivulle PHP:lla “Hei maailma” (esim. lukujen yhteenlasku). Asenna tarvittavat sovellukset. Aloita tyhjästä liverompulla.
  • b) Tee yksinkertainen PHP-ohjelma, joka laskee jotain käyttäjän syötteiden perusteella. Esim. suorakaiteen ala korkeudesta ja leveydestä, painoindeksi (BMI) pituudesta ja painosta tai syntymäaika syntymävuodesta. Vinkkejä: php.net: Manual: English: Simple tutorial: Forms. Kun julkaiset PHP-lähdekoodia WordPressissa, muista valita tekstin tyyliksi CODE, jotta sisennykset ja muut merkinnät näkyvät oikein.

Olenkin jo kerran kirjoitellut tänne raporttia Apache-webpalvelimen asennuksesta, joten en sitä nyt tee. Vaan hyppään suoraan koodin kirjoittamiseen websivulle.

Uusi läppärini saapui, joten työympäristö on nyt hieman erilainen.

Tietokoneen kokoonpano ja työympäristö:

  • Malli: Fujitsu Lifebook AH532
  • Suoritin: Intel Core i3-2328M 2.2GHz
  • Näytönohjain: Intel HD Graphics 3000
  • Muisti: 4Gb DDR3
  • Käyttöjärjestelmä: Ubuntu 12.04 LTS 64-bit

Ongelma I

Apachen asennus onnistui normaalisti. Asennuksen jälkeen kokeilin toimivuutta kirjoittamalla URL-kenttään “localhost” – Apache toimi normaalisti.

Tämän jälkeen loin tarvittavat kansiot websivua varten. Poikkeuksena viime postaukseen, vaihdoin index.html nimen index.php.

Kun kirjoitin selaimen URL-kenttään “localhost/~juho/index.php alkoi selain lataamaan .php-tiedostoa, eikä näyttänytkään sitä suoraan ruudulla.

Pienen googlettamisen jälkeen tajusin, etten ollut asentanut Apacheen php-pluginia. Tein sen komennoilla:

sudo apt-get install libapache2-mod-php5filter

sudo apt-get install libapache2-mod-suphp

Apachlle restart ja tämän jälkeen kotisivu näyttäytyi normaalisti.

Hei maailma

Kotisivun asennus Ubuntulle onnistui. Seuraavaksi tein pienen “Hei maailma” tervehdyksen PHP:lla.

Tein uuden tekstitiedoston nimeltä index.php ja kirjoittelin sinne pätkän koodia nanolla.

compt

Ja tältä se näytti websivulla:

awwyeah

I have no idea what I’m doing

EDIT: “Width” pitäisi olla “Lenght”.

PHP on hirveää, tämä  ei meinaa toimaa millään.

Päätin tehdä PHP:llä/HTML:llä pienen laskimen, joka laskisi kolmion ja suorakaiteen pinta-alan, eli kertoisi kaksi lukua keskenään.

Meinasin rage quittaa monta kertaa, sillä PHP on aivan hirveän epäkäytännöllinen mielestäni.
Lopulta sain säädettyä tälläisen koodin, joka vihdoinkin teki mitä halusin:

phplaskin

Koska Java on minulle tuttu, tein ohjelman omasta mielestäni helpoimmalla tavalla, eli muuttujilla.  Heti alussa määritän muuttujat $value1, $value2 ja $result.

$value1 ja 2 ovat käyttäjän määriteltävissä, kun taas $result on muuttujien tulo.

Käyttäjä määrittää muuttujat ja ohjelma kutsuu toiminnon mult.php ja ilmoittaa muuttujan $result arvon.

Vaikein kohta tässä koodissa oli se, että tajusin nimetä ohjelman mult.php. Eli, kun ohjelma hakee tiedostoa mult.php se hakee itsensä ja siten toteuttaa tuon viimeisen komennon, eli printtaa $resultin,

Selaimessa ohjelma näyttää tältä:

selaimessa

ja ilmoittaa vastauksen näin:

done'd

EDIT: Kommentoin koodin.

Sama Javalla

Halusin testata miten saman ohjelman tekeminen onnistuu Javalla, kun PHP:lla se tuntui niin kankealta.

javallasama

Mielestäni Javalla koodista tuli selkeämpi ja ennen kaikkea helpompi kirjoittaa. Seuraavana ongelmana olisikin saada Java-koodi websivulle.

EDIT: Java lisätty.