Stephen Fry

"Education is the sum of what students teach each other in between lectures and seminars. " - Stephen Fry

Tuesday, 8 January 2013

Quick Guide: Remotely adding a new user on Ubuntu 12.04

In the following is a quick guide to creating a new user (we will be calling this user "username") on a Amazon Cloud EC2 instance with Ubuntu 12.04 AMI

CREATING NEW USER

We will begin by adding the new user and setting the new users password

$ sudo adduser <username>

This command will then take you though the setting up a password. You can check the users that you now have my opening the /etc/passwd file

Now we are going to make use of a unix command called "visudo", this allow you to edit the sudoerrs file in a concurrent access safe way.  Before using visudo, we need to check that the default editor is the one that we would like and change it, if required:

sudo update-alternatives --config editor

Now you will be given a dialogue where you can select your favourite text editor.

visudo


Now add the following line to the file that has been opened:

<username> ALL=(ALL) ALL

Now exit the machine and log back in as ubuntu. 


You can now switch to this newly created user with 
$ su <username>
$ cd /home/<username>

GENERATING KEYS FOR SSH TO NEW USER

We are now going to generate the public key for public/private key pair that will be used later to SSH directly into this new user

ssh-keygen -b 1024 -f mykey -t dsa

This line has generated two files, the public key paws.pub and the private key paws. To be able to ssh from a local machine to the new paws user on this remote machine, we need to place copy the contence of paws.pub into /home/paws/.shh/authorized_keys and we need to have a copy of the private key (called paws) on the local machine


$ mkdir .ssh
$ chmod 700 .ssh
$ cat mykey.pub > .ssh/authorized_keys
$ chmod 600 .ssh/authorized_keys

Now that we have the key we need to transfer this key on to our local machine and generate the private key



$ sudo chown <username>:ubuntu .ssh
$ sudo cp mykey /home/ubuntu


$ sudo chown <username>:ubuntu .ssh/authorized_keys

$ sudo chmod 777 /home/ubuntu/mykey


Logout and return to local machine
$ scp -i originalkey.pem ubuntu@<URL-of-server>:/home/ubuntu/mykey mykey

Now you can ssh into your remote machine as this new user:

chmod 400 mykey ssh -i mykey <username>@url-of-server






Monday, 7 January 2013

Quick Guide : Amazon Cloud EC2

The following is a quick guide to setting up an virtual server on Amazon Cloud EC2:

SETUP


1) Login to AWS Management Console using your Amazon account and navigate to EC2

2) In the top right hand corner, check that the location of the servers is the one that you would like to use, I will be using Ireland

3) In the "Getting Started" section of the EC2 dashboard, select Launch instance to create a new virtual server

4) I will be demonstrating the "Classic Wizard"

5) Select the Amazon Machine Image (AMI) that you would like to use, I will be using the Amazon Linux AMI 2012.09, 64bit edition 

6) Enter the instance details, I am going to be creating 1 micro instance on EC2 so I've not changed any of the options on this page or the following Advanced Instance Options page or Storage Device Configuration page

7) Now you can create tags, using tags for your instances is really useful so I highly recommend it. I've set the key and value to "PAWS-router-management-server"

8) Creating a public/private key is vital for using SSH to access your virtual server. Give the private key a sensible name and download it

9) Creating a new security group is highly recommended, otherwise you can use make use the default group. I will be accessing the server using SSH so I've opened up port 22 to SHH 

10) Review the opinions you have chosen and save  

ACCESS


1) If you navigate to the "instances" page, you will now be able to see your newly created instance. Selecting your instance will give you access to more detailed information 

2) To access your new instance, open the terminal and locate the private key you downloaded during set up

3) Change the permissions on the key using: $ chmod 400 <name-of-key>

4) Connect via SSH using: $ ssh -i <name-of-key> <public-DNS-name-of-server>

More details on the Amazon Linus AMI are available at  http://aws.amazon.com/amazon-linux-ami/ . Its useful to note that there is no root password, you can't SSH in as root or use su but if you use sudo, no password is required and that the package manager used is yum