Thursday 29 September 2016

SSHenanigans

OK so today I have been going all over the place in order to connect to the PC currently less than 10 inches away from my feet.

Recently I have had a head cold, which as you probably know makes you just want to lie on the couch drinking honey and lemon... Unfortunately for me I had some work to do so rather than go into the office I emailed our network guy and asked him if he could give me access to the computer under my desk via SSH. Not a problem.

He suggested that I configure my ssh server to require both a key and a password. This made sense as having a key and knowing a password is better that just knowing a password or just having a key.

I set up a new ssh key using the ssh-keygen command and then copied the key to the PC under my desk and also edited the ssh_config file to include the line 'AuthenticationMethods publickey,password'

Everything worked as it should and I was able to do some work on that day.

The next day I got into work and realised I did not have the key on my main work PC that I needed to access the PC under my desk...this key was currently on my laptop at home (my head so full of mucus forgot to remind me to make a copy).

I started thinking about maybe walking home to get a copy of the key when I remembered that I had a raspberry pi at home which I could connect to via SSH. I connected to the mini server and scanned my network for my laptop (which, fortunately, I had left on while updating). I found the IP address for my laptop and connected to that via SSH. I was then able to copy the key back to my main computer and use the ssh-add command to install it. Finally I now had access to the PC under my desk *phew*..

Tuesday 27 September 2016

Learning Node.js

Node.js has always looked interesting to me, yet I have never explored it properly.

Every time I hear people mention Node.js its almost always followed by the words "web-server", so naturally I assumed Node.jswas a light weight web-server. Turns out (by just Googling node.js) that it is in fact just a JavaScript Run-time.

Once I installed Node I realised I could just run the following in a console:

$ node
> console.log('Hello');
Hello
undefined

Undefined is returned because node returns the return value of each command. This command has no return value. 

The reason people always mention web-servers is because its incredibly easy to create a basic web-server with node:

web-server.js

var http = require('http');

http.createServer(function (req, res) {
  res.writeHead(200, {'Content-Type': 'text/plain'});
  res.end('Hello World\n');
}).listen(8080);

console.log('Server running on port 8080.');

Now running node web-server.js will launch the web-server, going to http://localhost:8080 will show the text.

Node.js has a very large number of library's which can be used to do almost anything. One project I am quite keen on is a drag and drop page which will parse a CSV file and output relevant data. I'm going to be working on this over the next few hours and I will update this post once complete.