rstudio / plumber

Turn your R code into a web API.
https://www.rplumber.io
Other
1.39k stars 256 forks source link

Failing SSH connection with DigitalOcean in Windows #150

Closed cvmartin closed 7 years ago

cvmartin commented 7 years ago

Hi; I am impressed by the possibilities of plumber, and I tried to host an API with DigitalOcean. However, the SSH connection seems to fail, both with my Windows PC and with an instance of a Windows Virtual Machine.

The steps that I follow, based on the official documentation, are:

  1. I install the most recent versions of analogseaand plumberfrom github repositories. I also run the most recent version of R studio. I do few a tests to confirm that I can deploy APIs locally without problem.

  2. I create a new SSH key with R studio through Tools > Global options > Git/SVN > Create RSA Key. I publish the public key in my DigitalOcean account settings > security. I check that the SSH key exists in the folder established by R studio (C:/Users/<USER>/.ssh/id_rsa) and that R can locate the file in my hard drive.

  3. I connect in an straightforward way with analogsea::droplets(). I can see the droplets that I have created, and I can consult my keys with analogsea::keys(), too.

4- I run mydrop <- plumber::do_provision(). The message indicates that it starst to run well:

> my_droplet <- do_provision()
THIS ACTION COSTS YOU MONEY!
Provisioning a new server for which you will get a bill from DigitalOcean.
Using default ssh keys: <the key that I just created>
NB: This costs $0.00744 / hour until you droplet_delete() it
Waiting for create ..............

But things go wrong once the droplet is created and running. In my PC, I get:

no kex alg
Error: ssh failed
ssh -o BatchMode=yes -o StrictHostKeyChecking=no -o UserKnownHostsFile=C:\Users\cvare\AppData\Local\Temp\RtmpCS9BJZ/hosts root@45.55.6.84 "fallocate -l 4G /swapfile \
&& chmod 600 /swapfile \
&& mkswap /swapfile \
&& sudo swapon /swapfile \
&& sudo echo \"/swapfile   none    swap    sw    0   0\" >> /etc/fstab"
In addition: Warning message:
running command 'ssh -o BatchMode=yes -o StrictHostKeyChecking=no -o UserKnownHostsFile=C:\Users\cvare\AppData\Local\Temp\RtmpCS9BJZ/hosts root@45.55.6.84 "fallocate -l 4G /swapfile \
&& chmod 600 /swapfile \
&& mkswap /swapfile \
&& sudo swapon /swapfile \
&& sudo echo \"/swapfile   none    swap    sw    0   0\" >> /etc/fstab"' had status 255 

For what I have researched, no kex alg may be an indication that the SSH client used is outdated; I am not sure what method does R studio use as a client; I can connect normally via SSH with a droplet, using PuTTY as a client.

Following the steps mentioned above in another Windows system (a virtual machine) generates another error message:

Warning: Permanently added '104.131.88.253' (ECDSA) to the list of known hosts.
Permission denied (publickey).
Error: ssh failed
ssh -o BatchMode=yes -o StrictHostKeyChecking=no -o UserKnownHostsFile=C:/PROGRA~1/MIE74D~1/RSERVE~1/R_SERVER/o16n/rserve/workdir/tmp\Rtmps5O5CN/hosts root@104.131.88.253 "fallocate -l 4G /swapfile \
&& chmod 600 /swapfile \
&& mkswap /swapfile \
&& sudo swapon /swapfile \
&& sudo echo \"/swapfile   none    swap    sw    0   0\" >> /etc/fstab"
In addition: Warning message:
running command 'ssh -o BatchMode=yes -o StrictHostKeyChecking=no -o UserKnownHostsFile=C:/PROGRA~1/MIE74D~1/RSERVE~1/R_SERVER/o16n/rserve/workdir/tmp\Rtmps5O5CN/hosts root@104.131.88.253 "fallocate -l 4G /swapfile \
&& chmod 600 /swapfile \
&& mkswap /swapfile \
&& sudo swapon /swapfile \
&& sudo echo \"/swapfile   none    swap    sw    0   0\" >> /etc/fstab"' had status 255 

Here it seems that the droplet is recognized, but the key is not localized in the client side (even when it is in the right directory for R studio to read it).

A quick search shows that the process is straightforward at least in Mac, where it is also easier to work with SSH keys. I know that the development of plumber is ongoing, and perhaps I am not the only one who has problems connecting plumber and DigitalOcean from windows.

In any case, thanks for your amazing job so far! I am already thinking about the great possibilites that plumber can offer.

trestletech commented 7 years ago

Great bug report! And thanks for your patience.

Unfortunately this could be a wide variety of issues. To narrow the number of moving pieces, I'd recommend starting by hitting the analogsea API directly to create an instance and make sure that you can interact with it.

A simple test like

droplet <- analogsea::droplet_create(image="ubuntu-16-04-x64")
analogsea::debian_add_swap(droplet)

would help you more quickly measure whether or not your SSH connection was working. There may be some things that you need to debug outside of plumber just to get the above working (e.g. check the permissions on your SSH keys chmod 600; if they're not properly permissioned they might be silently ignored). I believe RStudio just looks for an existing version of SSH on your system. I unfortunately don't have access to a Windows machine so I'm not sure what the state of the art is on getting current SSH and git installed, but updating to current versions of those would probably help. GitHub usually does good work in this space; perhaps https://git-for-windows.github.io/ is useful?

Sorry I can't be of more use. But if you're able to get the above commands working and plumber is STILL not working, then there must be something wrong with the Plumber config, so I'd be able to diagnose a little deeper at that point.

cvmartin commented 7 years ago

Hi Jeff, thank you very much for your reply. Apparently there is something wrong with my SSH connection; running in my windows laptop

droplet <- analogsea::droplet_create(image="ubuntu-16-04-x64")
analogsea::debian_add_swap(droplet)

Throws an Error: ssh failed message. This is weird, because I can use SSH with PuTTY normally. Anyway, plumber happens to work perfect in an R studio server hosted, for instance, in Amazon EC2, so I do not feel the need to use a Windows machine for the task anymore.

Before posting my issue I browsed over GitHub documentation, and apparently connecting it to Rstudio using SSH is also messy; I haven't go deeper. I guess that if my issue cannot be replicated in other Windows systems, I must have some obscure option in the registry misconfigured or something. In any case, thank you very much for your reply!

trestletech commented 7 years ago

Sure thing. Sorry we weren't able to get to the bottom of it.

Schumzy commented 6 years ago

Hi @cvmartin

"Glad" to report I am having the same issue, did you ever figure out how to get it to deploy. I have gone through every "fix" here on github, as well as some stackoverflow issues to no avail.

If you are game and with help from @trestletech we may be able to get to the bottom of it and come up with a solution that others can come by later.

Thanks.

cvmartin commented 6 years ago

Hello @Schumzy ,

I keep benefiting from plumber, and definetly I am willing put some time in helping to fix the issue. The problem is, at the time I couldn't find even a lead on how to solve the problem, and I don't know how could I do it now.

My current approach with plumber is use a more "manual" configuration. I have a droplet with Rstudio server, plumber and a bunch of packages installed, and then I use pm2 (as described in plumber documentation) to deploy the services. This approach requires more boilerplate, but pm2 offers very fine control and reporting of errors, so now it is my favourite option instead of deploying a droplet from an Amazon EC2 instance (using linux, that method always worked well for me).

Schumzy commented 6 years ago

Hi @cvmartin Thanks for the response. I'm glad you figured out how to do it manually. That's great news.

Can we take this off line and maybe you can help me build my own manual plumber on DO? I am very new to this sort of thing and have tried several times to get it going, but to no avail. I have tried deploying Rstudio and running the plumber server code, but haven't been able to.

cvmartin commented 6 years ago

Hello @Schumzy,

I can give you a hand. I have written my own notes on how to run plumber with pm2 in an AWS EC2 instance (I find it also easier if the instance runs Rstudio server):

https://snippets.cacher.io/snippet/6793044c7332af5315fe (writtem in R markdown)

This should work with Digital Ocean, too.

Schumzy commented 6 years ago

Thanks!! @cvmartin Much Appreciated, will give it a try!

I was going through the rplumber.io doc on pm2 and your notes together may make it useful.

I like you did it via AWS EC2, makes sense. I don't quite follow your points about deploying on AWS. but will try first.