jerrysu / gulp-rsync

Gulp plugin for deploying files via rsync
119 stars 51 forks source link

How should I rsync with Amazon EC2 using *.pem key? #45

Open owen26 opened 7 years ago

owen26 commented 7 years ago

The rsync command would looks similar to this: rsync -rave "ssh -i /path/to/my/key.pem" example/* username@example.com:/var/www/html/example/

I'm wondering how do I achieve the same thing on gulp-rsync ?

capa89k commented 6 years ago

I am not sure if gulp-rsync support private/public key option for connection, but I suppose you can configure your ssh client in order to use the key.pem file whenever you connect to a specific host.

Just create a file config inside the folder $HOME/.ssh/ and write something like this:

Host example
        HostName example.com
        Port 22
        User username
        IdentityFile /path/to/my/key.pem

Then you can connect with gulp-rsync using as hostname the label name "example".

var rsyncConf = {
    ...
    hostname: 'example',
    username: 'username',
    ...
};
sangtcao commented 5 years ago

Just recently came into this issue and managed to put it together. Since no one else on the web posted a solution, figured I'd do my duty here and pass it along. Hope it can still be useful to others:

gulp-rsync doesn't support this by default, but back in 2015 there was an added feature for any custom options when running the command (https://github.com/jerrysu/gulp-rsync/issues/17). You can attach the -e option to your shell command like so:

var gulp = require('gulp');
var rsync = require('gulp-rsync');

gulp.task('deploy', function() {
  gulp.src('build/**')
    .pipe(rsync({
      username: 'user',
      hostname: 'host',
      destination: '~/',

      options: {
        "e": "ssh -i <local-path-to-key-file>"
      }

    }));
});