如何在 gulp-rsync 和 cygwin 中使用 ssh 密钥
How to use ssh key with gulp-rsync and cygwin
我正在使用 gulp 任务来部署我的应用程序,就像这样(在这个例子中我省略了实际值)
gulp.task('deploy', function () {
return gulp.src(config.deployFiles)
.pipe(rsync({
root: 'build/',
hostname: 'hostname',
username: 'username',
destination: 'destination'
}));});
但是,命令失败
gulp-rsync:权限被拒绝(公钥)。
注意:我可以通过 ssh 访问远程服务器,关键是如何告诉 cygwin 使用正确的 ssh 密钥以便 gulp-rsync 可以使用它?
这是我目前找到的解决方案。在 cygwin 终端中 运行
ssh-host-config
它将在 cygwin/etc 文件夹 (/etc/ssh_config) 中创建一个配置文件。然后,向该文件添加一个主机条目
Host hostnameToUse
Hostname xx.xx.xx.xx.xx
Port 22
IdentityFile D:\keys\vps
然后将 gulp 任务中的主机名更新为 'hostnameToUse'
gulp 部署工作:
gulp-rsync:正在发送增量文件列表....
你是对的@ojb。当我想使用 gulp 将我的生产就绪代码作为我的自动化工作流程的一部分在线推送时,我也陷入了类似的境地。
在gulp-rsync
中基本上没有标准参数作为ssh_key_location传递。因此,解决方法是使用 ssh 配置文件创建本地 伪主机名 。此过程使用 伪主机名 掩盖 实际主机名 。
(ec2-xx-xxx-xxx-xxx.ap-west-2.compute.amazonaws.com + key) =>
hostname.com
由于没有关于如何解决此问题的适当文档,因此这里为可能遇到此问题的每个人提供了详细的操作方法
第一步:更新 ~/.ssh/config 文件以使其工作:$ ssh hostname.com
Host hostname.com
HostName ec2-xx-xxx-xxx-xxx.ap-west-2.compute.amazonaws.com
User ec2-user
IdentityFile ~/<path-to-file>/keyfile.pem
第二步:
将此添加到您的 gulp 函数中
// Dirs and Files to sync
rsyncPaths = ['directory-names', './file-name',....];
// Default options for rsync
rsyncConf = {
progress: true,
incremental: true,
relative: true,
emptyDirectories: true,
recursive: true,
clean: true,
exclude: [],
};
第三步:在gulp
中创建以下函数
//something-on-top
return gulp.src(rsyncPaths)
.pipe($.rsync(rsyncConf));
疑难解答:
1.检查文件是否有400访问权限
2.检查$ ssh hostname.com
是否有效
最近才遇到这个问题,并设法把它放在一起。由于网络上没有其他人发布解决方案,我想我会在这里尽我的职责并传递它。希望它仍然对其他人有用:
gulp-rsync 默认情况下不支持此功能,但早在 2015 年,当 运行命令(https://github.com/jerrysu/gulp-rsync/issues/17)。您可以将 -e
选项附加到您的 shell 命令,如下所示:
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>"
}
}));
});
我正在使用 gulp 任务来部署我的应用程序,就像这样(在这个例子中我省略了实际值)
gulp.task('deploy', function () {
return gulp.src(config.deployFiles)
.pipe(rsync({
root: 'build/',
hostname: 'hostname',
username: 'username',
destination: 'destination'
}));});
但是,命令失败
gulp-rsync:权限被拒绝(公钥)。
注意:我可以通过 ssh 访问远程服务器,关键是如何告诉 cygwin 使用正确的 ssh 密钥以便 gulp-rsync 可以使用它?
这是我目前找到的解决方案。在 cygwin 终端中 运行
ssh-host-config
它将在 cygwin/etc 文件夹 (/etc/ssh_config) 中创建一个配置文件。然后,向该文件添加一个主机条目
Host hostnameToUse
Hostname xx.xx.xx.xx.xx
Port 22
IdentityFile D:\keys\vps
然后将 gulp 任务中的主机名更新为 'hostnameToUse' gulp 部署工作:
gulp-rsync:正在发送增量文件列表....
你是对的@ojb。当我想使用 gulp 将我的生产就绪代码作为我的自动化工作流程的一部分在线推送时,我也陷入了类似的境地。
在gulp-rsync
中基本上没有标准参数作为ssh_key_location传递。因此,解决方法是使用 ssh 配置文件创建本地 伪主机名 。此过程使用 伪主机名 掩盖 实际主机名 。
(ec2-xx-xxx-xxx-xxx.ap-west-2.compute.amazonaws.com + key) => hostname.com
由于没有关于如何解决此问题的适当文档,因此这里为可能遇到此问题的每个人提供了详细的操作方法
第一步:更新 ~/.ssh/config 文件以使其工作:$ ssh hostname.com
Host hostname.com
HostName ec2-xx-xxx-xxx-xxx.ap-west-2.compute.amazonaws.com
User ec2-user
IdentityFile ~/<path-to-file>/keyfile.pem
第二步:
将此添加到您的 gulp 函数中
// Dirs and Files to sync
rsyncPaths = ['directory-names', './file-name',....];
// Default options for rsync
rsyncConf = {
progress: true,
incremental: true,
relative: true,
emptyDirectories: true,
recursive: true,
clean: true,
exclude: [],
};
第三步:在gulp
中创建以下函数//something-on-top
return gulp.src(rsyncPaths)
.pipe($.rsync(rsyncConf));
疑难解答:
1.检查文件是否有400访问权限
2.检查$ ssh hostname.com
是否有效
最近才遇到这个问题,并设法把它放在一起。由于网络上没有其他人发布解决方案,我想我会在这里尽我的职责并传递它。希望它仍然对其他人有用:
gulp-rsync 默认情况下不支持此功能,但早在 2015 年,当 运行命令(https://github.com/jerrysu/gulp-rsync/issues/17)。您可以将 -e
选项附加到您的 shell 命令,如下所示:
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>"
}
}));
});