我正在使用 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 key ,以便 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
是否有效
关于windows - 如何在 gulp-rsync 和 cygwin 中使用 ssh key ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40335149/