views:

63

answers:

2

I'm writing a ruby on rails service that will conect to various servers via SSH.

I want to generate the public/rivate key and store them in the database. Then the user will be able to view the public key and add it to there key authentication for SSH on their server.

The my service will contact the servers via Net::SSH and present the corresponding keys.

My questions is what API calls do I need to achive this. Most of the documentation assomes you'll be creating keys in the .ssh directory.

A: 

Can't you use ssh-keygen command ? I mean:

get passphrase and other parameters from web interface

validate, check etc. and then:

#!/usr/bin/env ruby
$VERBOSE=true

`ssh-keygen -f ~/sshkeyfile -t rsa -C "something"  -P "something else"`

Of course changing path to something more appropriate, and using options that you want.

Then read sshkeyfile and sshkeyfile.pub from your choosen location
store it in db etc.

Casual Coder
I suppose that is one way to do it. I was hoping to stay away from the filesystem. i.e. Create the keys into a string and then store. Then when conenctiong with Net::SSH present the keys as a string.
Ian Purton
Look at http://stackoverflow.com/questions/235759/opening-an-rsa-private-key-from-ruby
Casual Coder
A: 

I found out how to directly pass the keys to Net::SSH

Basically you can pass a PEM format private key using the :key_data option. Net::SSH can then generate the public key from that as it needs both.

Ian Purton