与flightplan一起部署时出现连接错误

时间:2015-05-04 20:23:22

标签: node.js

我正在使用flightplan运行此代码:

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

我不知道发生了什么。我正试图将其部署到数字海洋。我不确定是什么导致了这个问题。

1 个答案:

答案 0 :(得分:1)

您好像没有正确验证远程主机。您需要将SSH密钥添加到远程主机以进行无密码访问。

执行此操作的命令是

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

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

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