Skip to content
Advertisement

ssh using R system() command

When I try to connect computer A to computer B using ssh and R’s system() command, I get an error:

system('ssh root@Bs-ip-address')

ssh_askpass: exec(rpostback-askpass): No such file or directory
Host key verification failed.
lost connection

But if I enter the command in quotes into my Linux terminal (ssh root@Bs-ip-address) it works fine (ssh keys are set up for the correct user). How can I connect properly using R’s system() command? Or can you suggest a better way to connect?

It might have something to do with needing to enter ‘yes’ to the following prompt that arises within Linux:

The authenticity of host Bs-ip-address (Bs-ip-address) cant be established.
ECDSA key fingerprint is unique-fingerprint.
Are you sure you want to continue connecting (yes/no)?

After I enter ‘yes’ once in a putty session, the R system() command above will work. But I don’t want to have to enter into putty each time. (As a side note, I’m creating a number of identical Digital Ocean instances with pre-set ssh keys, and trying to connect to them from R, so entering a putty session each time for each new instance is not a workable option.) Can you send a ‘yes’ command using system()?

Advertisement

Answer

You could automate that acceptance (caveat: you have to be sure that the machines you’re about to access are trusted!).

If the hosts have rsa keys, for instance, you can do:

system( 'ssh-keyscan  -t rsa Bs-ip-address  >> ~/.ssh/known_hosts' )

HIH.

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement