I recently had to reflash my Nokia N9 because Bluetooth would no longer start. The reflashing itself is a story for another time (and maybe another blog post), but the process of restoring apps and stuff after the reflash made me think about how I interact with the N9 as a developer.
Until now when I have needed to move files onto the N9 I have connected via SSH using the password prompted in the N9's SDK Connectivity App. While this works well it is a bit cumbersome.
Then I reflected on how we interact with the Sailfish SDK and Emulator. Here we authenticate via RSA key files. No password needed. Much nicer, yet equally secure.
So this raised the question: can we apply the same technique to the N9? Can we connect to the N9 with a RSA key file?
After a little bit of googling and experimentation, the answer is a resounding yes; and it proves to be very easy.
I found the basic idea here: http://talk.maemo.org/showthread.php?t=41547. So thanks to Greygoo the author. My post takes a slightly simpler approach, and is specific to the N9.
Easy it may be: but please bear in mind that if you get this wrong, you may lose SSH access to your phone. Please take care, think with me; and you follow these instructions at your own responsibility.
Firstly we need to generate a key pair on our development host. In this case I will be using Apple-pip my MacBookAir. This will give us a public key and a private key. The private key will remain securely on Apple-pip (the client in the connection), and the public key will be put on to the connection server - the N9.
So on Apple-Pip: let's move the .ssh directory, then list what's already there
Now we will generate a key pair called n9_rsa, with an empty passphrase.
ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (~/.ssh/id_rsa): n9_rsa
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in n9_rsa.
Your public key has been saved in n9_rsa.pub.
The key fingerprint is:
The key's randomart image is:
+--[ RSA 2048]----+
| o |
| . . = E |
| + + o |
| . S o . |
| * = . . |
| o = . o .|
| o.o . . |
| o*oo.. |
Now if we ls again we should find 2 additional files,
* private key n9_rsa
* and the public key n9_rsa.pub
Now we need to transfer the public key to the N9
scp ~/.ssh/n9_rsa.pub firstname.lastname@example.org:/home/developer/
Then we connect to the N9 as we always have done, with password:
Once connected, move to the .ssh directory.
Now we want to concatenate the contents of the public key to the authorized_keys file
cat ../n9_rsa.pub >> authorized_keys
Then we cleanup by removing the public key file from the N9.
Exit, and try reconnecting from your development host as follows:
ssh -i ~/.ssh/n9_rsa email@example.com