pm2-deploy: Cannot clone the repo via pm2 deploy

I can git clone my repo in the server ssh terminal. However, when I use pm2 deploy ecosystem.json dev setup to setup my project, it shows the following message.

Initialized empty Git repository in /home/imfoyo/deploy/shb0577/development/source/.git/
Permission denied (publickey).
fatal: The remote end hung up unexpectedly

  failed to clone

Deploy failed

My ecosystem.json file is as follows:

{
  /**
   * This is a sample configuration file for PM2
   */

  /**
   * Here we declare the apps that must be managed by PM2
   * All options are listed here:
   * https://github.com/Unitech/PM2/blob/master/ADVANCED_README.md#json-app-declaration
   *
   */
  apps : [

    // First application
    {
      name      : "myrepo",
      script    : "bin/www",
      env: {
        COMMON_VARIABLE: "true"
      },
      env_production : {
        NODE_ENV: "production"
      }
    }

  ],


  /**
   * PM2 help you to deploy apps over your servers
   * For more help go to :
   * https://github.com/Unitech/PM2/blob/master/ADVANCED_README.md#deployment-pm2--090
   */
  deploy : {
    production : {
      user : "imfoyo",
      host : "192.168.199.174",
      ref  : "origin/master",
      repo : "git@bitbucket.org:belife/myrepo.git",
      path : "/var/www/production",
      "post-deploy" : "pm2 startOrRestart ecosystem.json --env production"
    },
    dev : {
      key  : "/home/imfoyo/.ssh/imfoyo.lan",
      user : "imfoyo",
      host : "192.168.199.174",
      ref  : "origin/master",
      repo : "git@bitbucket.org:belife/myrepo.git",
      path : "/home/imfoyo/deploy/development",
      "post-deploy" : "npm install && pm2 startOrRestart ecosystem.json --env dev",
      env  : {
        NODE_ENV: "dev"
      }
    }
  }
}

About this issue

  • Original URL
  • State: closed
  • Created 9 years ago
  • Reactions: 1
  • Comments: 16 (1 by maintainers)

Most upvoted comments

‘ssh_options’: ‘ForwardAgent=yes’

Permission denied (publickey).

Your remote server is not allowed to git clone (you forgot to add your server public key to bitbucket)

You need to use a key that doesn’t have a passphrase. I ended up creating a ~/.ssh/config with so that I could use different keys for different Github projects.

there is also a “secret” “forward-agent” option to use the same key for the server and the git

I had this same issue, and it’s because I was using a key that had a passphrase. I was scratching my head until I saw this issue and @alecho’s comment above.

@Unitech My server is centos. I don’t know why each time I login to the server, I should manually run

$ eval `ssh-agent -s`
$ ssh-add /path/to/mykey

However, if I put these commands to my .bashrc file, scp will not work.

I’ve had success running using forward-agent: “yes”, however I understand this introduces some security issues. So far I have not been able to deploy from local to remote, even in the case that remote is able to successfully connect to git server and is able to clone when connected via ssh (clone fails when initiated by pm2 from the local machine)