Reimplement the SSH key management.

Cherry-picked from essex version.