Giter VIP home page Giter VIP logo

ssh's Introduction

SSH

Project Status: Active โ€“ The project has reached a stable, usable state and is being actively developed. Build Status AppVeyor Build Status Coverage Status CRAN_Status_Badge CRAN RStudio mirror downloads

Secure Shell (SSH) Client for R

Installation

This package is available on CRAN and can be installed via:

install.packages('ssh')

Alternatively it can be installed from source using devtools:

remotes::install_github('ropensci/ssh')

Installation from source on MacOS or Linux requires libssh (the original libssh, not the unrelated libssh2 library). On Debian or Ubuntu use libssh-dev:

sudo apt-get install -y libssh-dev

On Fedora we need libssh-devel:

sudo yum install libssh-devel

On CentOS / RHEL we install libssh-devel via EPEL:

sudo yum install epel-release
sudo yum install libssh-devel

On OS-X use libssh from Homebrew:

brew install libssh

Using conda (need a conda R environment conda create -n Renv r-base r-essentials)

conda install --channel conda-forge r-ssh

If you have issues with the conda installation please submit an issue in conda-forge/r-ssh-feedstock

Getting Started

First create an ssh session by connecting to an SSH server. You can either use private key or passphrase authentication:

session <- ssh_connect("[email protected]")

You can use the session in subsequent ssh functions below.

Run a command

Run a command or script on the host while streaming stdout and stderr directly to the client.

ssh_exec_wait(session, command = c(
  'curl -fOL https://cloud.r-project.org/src/contrib/Archive/jsonlite/jsonlite_1.5.tar.gz',
  'R CMD check jsonlite_1.5.tar.gz',
  'rm -f jsonlite_1.5.tar.gz'
))

If you want to capture the stdout/stderr:

out <- ssh_exec_internal(session, "R -e 'rnorm(100)'")
cat(rawToChar(out$stdout))

Using 'sudo'

Note that the exec functions are non interactive so they cannot prompt for a sudo password. A trick is to use -S which reads the password from stdin:

out <- ssh_exec_wait(session, 'echo "mypassword!" | sudo -s -S apt-get update -y')

Be very careful with hardcoding passwords!

Uploading and Downloading via SCP

Upload and download files via SCP. Directories are automatically traversed as in scp -r.

# Upload a file to the server
file_path <- R.home("COPYING")
scp_upload(session, file_path)
# Download the file back and verify it is the same
scp_download(session, "COPYING", to = tempdir())
tools::md5sum(file_path)
tools::md5sum(file.path(tempdir(), "COPYING"))

Create a Tunnel

Opens a port on your machine and tunnel all traffic to a custom target host via the SSH server.

ssh_tunnel(session, port = 5555,target = "ds043942.mongolab.com:43942")

This function blocks while the tunnel is active. Use the tunnel by connecting to localhost:5555 from a separate process. The tunnel can only be used once and will automatically be closed when the client disconnects.

Disconnect

When you are done with the session you should disconnect:

ssh_disconnect(session)

If you forgot to disconnect, the garbage collector will do so for you (with a warning).

ssh's People

Contributors

abusjahn avatar espinielli avatar jeroen avatar jxu avatar ldalby avatar lucharo avatar maelle avatar tonosam avatar yogat3ch avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.