Establish ssh connection from RStudio on linux

I am trying to pull a file from another computer into the R environment in RStudio on Centos 6

I first tried this in regular R, and when I issued

readLines(pipe( 'ssh root@X.X.X.X "cat /path/somefile.sh"' )) 

it correctly asks me for the password for my ssh key and reads the contents.

However, if the same command is executed from RStudio, all I get is:

 ssh_askpass: exec(rpostback-askpass): No such file or directory Permission denied, please try again. ssh_askpass: exec(rpostback-askpass): No such file or directory Permission denied, please try again. ssh_askpass: exec(rpostback-askpass): No such file or dire Permission denied (publickey,gssapi-with-mic,password). 

I suspect that the reason is that rstudio on centos actually uses the user rstudio-server (and gui is provided in the browser). Does anyone know how to properly access ssh'd resources?

UPD: after execution

 Sys.setenv(PATH = paste0(Sys.getenv('PATH'), ':/usr/lib/rstudio-server/bin/postback')) 

as suggested below, it will not output crawl errors, but it still doesn't work. Now it seems that the console expects the command to be executed indefinitely

+6
source share
1 answer

rpostback-askpass is part of RStudio. This can help add its location ( /usr/lib/rstudio-server/bin/postback on my system) to PATH so ssh can find it:

 Sys.setenv(PATH = paste0(Sys.getenv('PATH'), ':/usr/lib/rstudio-server/bin/postback')) 

UPDATE RCurl has a scp function to copy files on top of ssh. See this answer for more details. If you run your scripts using RStudio, you can use your API to enter the ssh password interactively with hidden input:

 pass <- .rs.askForPassword("password?") 

and rstudioapi can help determine if a script is running using RStudio or not.

+3
source

Source: https://habr.com/ru/post/970323/


All Articles