Reimplement the SSH key management.

Cherry-picked from essex version.

Partially solves Issue #34