ssh using R system() command

五迷三道 提交于 2020-02-22 08:01:12

问题


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()?


回答1:


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.



来源:https://stackoverflow.com/questions/32173180/ssh-using-r-system-command

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!