gextra
gextra

Reputation: 8895

How to connect through SSH in Erlang using a PEM key file

Using the ssh module in erlang, it is possible to establish a connection to a remote server.

There are several options indicated in such API, but it is unclear to me which one would allow me to establish a connection that is enforced only by authenticating using a .pem file.

For example, using the ssh command in an OS shell, I can connect to my host using this:

ssh -c 3des -2 -l root -i MYPERMISSIONFILE.PEM myhost.mydomain.com -p 22

In Erlang, the ssh module has a fd option { fd,

ssh:start().
ssh:connect("myhost.mydomain.com",22, ???????? ).

There are several security options, I beleive the content of the .pem file could be used as one of the security optins, but that would be 1700 characters! There is an option to use a file descriptor [ {fd, } ], but it is unclear to me if that is the way to achieve this.

Upvotes: 3

Views: 703

Answers (1)

Tom H.
Tom H.

Reputation: 510

I was able to get it working by copying the pem file using the name id_rsa in a folder other than ~/.ssh (so it doesn't overwrite any keys you have set up already), e.g. ~/keys, and then passing into ssh:connect/3 the option {user_dir, "~/keys"}. It picks up the renamed pem as the rsa key.

Upvotes: 3

Related Questions