Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Establishing ssh connection from within RStudio on linux

Tags:

linux

ssh

r

rstudio

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

I've tried it in plain R first and when I issue

readLines(pipe( 'ssh [email protected] "cat /path/somefile.sh"' ))

it correctly asks me for the password of 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 because rstudio on centos actually uses rstudio-server user (and gui is provided in a browser). Does anyone know how to properly access ssh'd resources from it ?

UPD: after executing

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

as suggested below it won't output askpass errors, but it still does not work. Now it seems that the console is waiting for the command to execute indefinitely

like image 544
Zeks Avatar asked Jun 04 '14 15:06

Zeks


1 Answers

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

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

UPDATE RCurl has scp function for copying files over ssh connection. See this answer for details. If you are running your scripts with RStudio, you can use its API to enter the ssh password interactively with hidden input:

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

and rstudioapi can help to determine whether the script is launched by RStudio or not.

like image 196
Alex Vorobiev Avatar answered Sep 18 '22 00:09

Alex Vorobiev