Setting up Ubuntu Server 14.04 LTS

Install

This guide is primarily for my own reference; I run a basic server at home for Git repositories and test sites.

My preference is to run the Long Term Support version of Ubuntu Server. For my new machine I’ll be running 14.04 LTS which will have 5 years of support, so until 2019.

Basically I want to set it up and forget about it – what I don’t want to forget is how it’s set up.


Network

First things first – because this is a server and will primarily be accessed by applications and via SSH/sFTP, let’s make a few networking changes.

Static IP address

To make life easier I want the server to have a static IP address that is easy to remember – I have chosen 192.168.1.150

This number is based on my Plusnet routers addressing of 192.168.1.254

iface eth0 inet static
                address  192.168.1.150
                netmask  255.255.255.0
                gateway  192.168.1.254
                dns-nameservers  8.8.8.8  8.8.4.4

The snippet above is placed in your interfaces configuration:

sudo vi /etc/network/interfaces

This was based on the information from the Unixmen page:

To restart your interface use:

sudo ifdown eth0 && sudo ifup eth0

Your new IP address should be active. If not then you can also try rebooting the machine.

sudo reboot

SSH

From another machine you can log in to your server using OpenSSH as installed during the Ubuntu installation.

Log in

From Terminal:

ssh username@192.168.1.150

Type in your password when it prompts you and agree to any other messages.

Passwordless entry

Generate your key on a client machine, in my case a Mac Pro, though this is pretty much the same as most Linux distributions:

ssh-keygen -t rsa -b 4096

Follow the key generation instructions until you are returned to the command prompt.

To transfer the key to the servers authorised hosts file use the command below:

cat ~/.ssh/id_rsa.pub | ssh username@192.168.1.150 "mkdir ~/.ssh; cat >> ~/.ssh/authorized_keys"

This key can now also be used in applications such as Filezilla and Tower 2 as well.

Now that we have access to our server remotely and it can use passwordless entry, we can disable password access in the SSH config file:

sudo vi /etc/ssh/sshd_config

Change the value of the line below to:

PasswordAuthentication no

To apply the new configuration, restart the SSH server:

sudo service ssh restart

Logging more detail

To log more detail about what SSH is doing, change the value of the line below to:

LogLevel VERBOSE

To apply the new configuration, restart the SSH server:

sudo service ssh restart

To view the log use:

sudo vi /var/log/auth.log

 

Commands useful with SSH

Turn the machine off – shutting down and power off:

sudo shutdown -h now

Reboot the machine – shutting down and restart:

sudo reboot

Determine where you are in the file structure:

pwd

Clear the terminal window:

clear

LAMP

 


Git

Open Terminal and run the following command:

sudo apt-get install git-core

You’ll need to create a Git configuration file in your home directory – I’ll use vi, because it’s just so user friendly:

sudo vi ~/.gitconfig

You should now be starting from a fresh/empty file, close vi and run the following commands to add details to your configuration file:

git config --global user.name "gitUserName"
git config --global user.email user.email@domain.co.uk

If you use GitHub use the same details you use to access the web site. Git is now installed and your user details should be saved in the configuration file.

Get the latest updates

Adding the latest version of Git from their package repository – useful on Ubuntu LTS versions where the Ubuntu Universe version is older than the Git version:

sudo add-apt-repository ppa:git-core/ppa
sudo apt-get update
sudo apt-get upgrade

Mirror existing repositories

Mirroring your existing repositories to the new server

Setting up & using Git on Ubuntu

Installing Git and doing the initial set up is pretty straight-forward. I’m using Ubuntu 13.10 – open Terminal and run the following command:

sudo apt-get install git-core

You’ll need to create a Git configuration file in your home directory – I’ll use vi, because it’s just so user friendly:

sudo vi ~/.gitconfig

You should now be starting from a fresh/empty file, close vi and run the following commands to add details to your configuration file:

git config --global user.name "gitUserName"
git config --global user.email user.email@domain.co.uk

If you use GitHub use the same details you use to access the web site. Git is now installed and your user details should be saved in the configuration file.

Get the latest updates

Adding the latest version of Git from their package repository – useful on Ubuntu LTS versions where the Ubuntu Universe version is older than the Git version:

sudo add-apt-repository ppa:git-core/ppa
sudo apt-get update
sudo apt-get upgrade

Accessing GitHub

If you’re using GitHub as your central repository then you’ll need to do a few things to allow yourself access. First off you’ll need to install OpenSSH and create an authentication key. Once you’ve done that you will need to copy the contents of your public key and add it to your account on GitHub. Click on the account settings link on GitHub – it’s in the top right corner: github-account-links On the left hand side there is a link labelled ‘SSH keys’ – click that: ssh-link-in-left-panel-on-github The resulting page lists any keys you currently have associated to your account. In the top right of the content of the page you’ll have a link to ‘Add SSH key’: add-ssh-link-on-github The next page is quite straight-forward, give your key a title so you can identify it later and then paste the contents of your public key file into the other field: add-ssh-key-form-on-github Save your changes.

Using Git

Some common commands for everyday usage of Git from the command line. Change directory so you are in your repository – then run these commands depending on what you want to do.

Clone a repository

git clone git://github.com/path/to.git

Get status

git status

Update local

git pull

Commit changes

git add "path/to/file.ext"
git commit -m "A useful commit message"
git push

Or if you have a few changes to add at the same time you can run:

git add -A
git commit -m "A useful commit message"
git push