Archive

Posts Tagged ‘ifconfig’

Linux Server – Task 1: Complete One Course Exam

Course
Linux palvelimena [Linux server] by Tero Karvinen at Haaga-Helia University of Applied Sciences

Task
Complete an archived Työasemat ja tietoverkot [workstations and networks] course exam. I chose this one (in Finnish).

Testing environment
OS: Xubuntu Linux 13.10 “Saucy Salamander” 32-bit (persistent live USB drive)
System: HP EliteBook 2570p Notebook PC

Creating the user accounts
After booting to the desktop, I opened the terminal prompt (super key + t). I had previously set the keyboard layout to Finnish, but I could have changed it manually by executing $ setxkbmap fi in the terminal. Next I created user accounts for the users mentioned in the exam by running $ sudo adduser “user name” in the terminal, making sure to create each person an identifiable user name and a secure password.

Installing Apache and OpenSSH
I ran $ sudo apt-get update in the terminal to update the package list, and then installed Apache server and OpenSSH via the terminal by running $ sudo apt-get install apache2 openssh-server.

Testing Apache
I created a folder named public_html for testing purposes in my home directory by running $ mkdir public_html in the terminal. I then created an index.html file in the same folder with $ nano index.html, and added the following lines to it in order to create a valid HTML5 test page:

<!doctype html>
<html>
<head>
	<title>Test</title>
</head>
<body>
	<p>Hello World!</p>
</body>
</html>

I enabled the Apache2 Userdir Module by running $ sudo a2enmod userdir in the terminal. “Apache2 userdir module is used to create a webroot in the user’s home directory. By using userdir module each user that is in the system will have the Apache2 root directory with the folder name public_html in the home directory” (Ubuntu Server Guide).

Next I restarted the apache2 daemon via $ sudo service apache2 restart. Having completed this, I tested the HTML5 page in Firefox at localhost/~username/, which returned a page with the line “Hello World!”, verifying that the everything was working as intended.

Testing SSH and user home pages
To test SSH and creating home pages for users, I logged in as one of the users (pekkawinha) via SSH by entering $ ssh pekkawinha@localhost in the terminal, and then accepted the host’s authenticity and entered the password for Pekka Winha. Doing so was OK in this case because none of the users had yet been given their passwords, and thus couldn’t have logged in yet.

At this point I repeated the procedure for creating a public_html folder and index.html file (without sudo, as the user isn’t root), this time in pekkawinha’s home directory (/home/pekkawinha/public_html/index.html).

Creating the files while logged in as the user will give the user the permissions necessary to edit the files later, when they log in for the first time. I tested the page in Firefox (the same method as before), and found that everything was working as intended. I terminated the SSH connection with $ exit and returned to my own account.

Installing MySQL and phpMyAdmin
I installed MySQL and phpMyAdmin by entering $ sudo apt-get install mysql-server phpmyadmin in the console. Following my own LAMP installation instructions (in Finnish), I set the root password and selected the correct configuration options. The database for phpMyAdmin was configured with dbconfig-common. I navigated to localhost/phpmyadmin/ in Firefox and was greeted by a login prompt – the root user login details worked, as expected.

Enabling PHP for user directories
Next I needed enable PHP for the user directories. This was accomplished by entering $ sudo nano /etc/apache2/mods-available/php5.conf in the terminal, and editing the php5.conf, which in this case simply meant commenting out the last five lines of the file. Then I restarted the apache2 daemon with $ sudo service apache2 restart.

I logged in as pekkawinha via SSH again to verify that PHP was indeed working. I created a new file in public_html with $ nano index.php, and added the following lines:

<?php
print(37.4+4.4)
?>

After this I navigated to localhost/~pekkawinha/index.php in Firefox, and the result to my query was printed: 41.8. This verified that PHP was working properly. Finally, I used $ exit to terminate the SSH connection.

Creating a global mystatus shell script
The final piece to the puzzle was creating a global shell script named mystatus. I began by creating a new file in my home directory with $ nano mystatus. I added the following lines to it for showing a computer’s disk space and IP address. Since I’m using a live USB drive, I used ifconfig to cover all my bases, but you can use something like ip addr show wlan0 if you only use one computer.

#!/bin/sh
df -h
ifconfig

Next I gave the mystatus script the necessary permissions to run it by running $ chmod a+x mystatus in the terminal. Then I tested the script via $ ./mystatus. It worked as expected. Finally, I ran $ sudo mv mystatus /usr/local/bin to move the mystatus script, so that it was globally available to all users by simply entering $ mystatus in the terminal.

References
Linux Live USB Creator (http://www.linuxliveusb.com/)
Ubuntu Server Guide (http://ubuntuserverguide.com/2012/10/how-to-enable-and-configure-apache2-userdir-module-in-ubuntu-server-12-04.html)
Karvinen, Tero: Lessons 2014-1-24, Linux palvelimena [Linux server] (http://terokarvinen.com/2013/aikataulu-%E2%80%93-linux-palvelimena-ict4tn003-11-ja-12-kevaalla-2014)

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
Based on a course by Tero Karvinen, http://www.iki.fi/karvinen