使用飞行计划进行部署时出现连接错误

我正在使用飞行计划运行此代码:

var plan = require('flightplan'); var appName = 'personal-website'; var username = 'deploy'; var startFile = 'bin/www'; var tmpDir = appName+'-' + new Date().getTime(); // configuration plan.target('staging', [ { host: '104.131.153.117', username: username, } ]); plan.target('production', [ { host: '104.131.153.117', username: username, }, //add in another server if you have more than one // { // host: '104.131.93.216', // username: username, // agent: process.env.SSH_AUTH_SOCK // } ]); // run commands on localhost plan.local(function(local) { local.log('Copy files to remote hosts'); var filesToCopy = local.exec('git ls-files', {silent: true}); // rsync files to all the destination's hosts local.transfer(filesToCopy, '/tmp/' + tmpDir); }); // run commands on remote hosts (destinations) plan.remote(function(remote) { remote.log('Move folder to root'); remote.sudo('cp -R /tmp/' + tmpDir + ' ~', {user: username}); remote.rm('-rf /tmp/' + tmpDir); remote.log('Install dependencies'); remote.sudo('npm --production --prefix ~/' + tmpDir + ' install ~/' + tmpDir, {user: username}); remote.log('Reload application'); remote.sudo('ln -snf ~/' + tmpDir + ' ~/'+appName, {user: username}); remote.exec('forever stop ~/'+appName+'/'+startFile, {failsafe: true}); remote.exec('forever start ~/'+appName+'/'+startFile); }); 

这是我尝试部署时得到的错误:

 Error connecting to 104.131.153.117: Error: Authentication failure. Available authentication methods: publickey,password 

我不知道发生了什么事。 我正在试图将这部署到数字海洋。 我不知道什么是造成这个问题。

它看起来像你没有正确authentication到远程主机。 您需要将SSH密钥添加到远程主机以进行无密码访问。

这个命令是

 $ ssh-copy-id <user>@<host> 

如果您需要指定使用的确切密钥,请使用以下命令

 $ ssh-copy-id -i <path-to-.pub-file> <user>@<host>