9

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 root@X.X.X.X "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

Zeks
  • 2,265
  • 20
  • 32

1 Answers1

5

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.

Community
  • 1
  • 1
Alex Vorobiev
  • 4,349
  • 21
  • 29
  • Some progress, but it's still not working. it won't output errrors about askpass (it looks like it sees it now) but it won't give password promt either and it looks like system is just waiting for it because r simpy hangs for indefinite time. :( – Zeks Jul 04 '14 at 09:17
  • 1
    Can you use `scp` function from RCurl package? See my answer here: http://stackoverflow.com/questions/17347450/how-do-you-connect-to-a-remote-server-with-ssh-in-r/17347956#17347956. If you want to enter the password interactively, you can use `.rs.askForPassword("password?")` provided by RStudio – Alex Vorobiev Jul 08 '14 at 03:44
  • Yes, this works, thanks :) If you make this an answer I will be able to give you the bounty :) – Zeks Jul 08 '14 at 11:01
  • This only works if one wants to copy a file. If you want the result of any other command you still have the same problem. Would still be interested in a solution, as extending the path does not work for me either. P.s. code works fine from R in a shell, just not in RStudio. – user1965813 Aug 30 '18 at 11:48