Unitech / pm2-deploy

Deploy part of PM2
http://pm2.keymetrics.io/docs/usage/deployment/
MIT License
178 stars 72 forks source link

Protected ssh key with passphrase cannot git clone/pull #170

Open Unitech opened 5 years ago

Unitech commented 5 years ago

https://github.com/Unitech/pm2/issues/4072

albertosantini commented 4 years ago

Well, I worked out the task using a key with passphrase.

Basically the passphrase is only used to login into target server. The same ssh key, used to clone the repo on target server, is not protected with a passphrase.

I try to explain my setup.

To login on target server:

To clone the repo on target server:

Yes, we have the same pub key in the authorized_keys and in the file id_rsa.pub. Yes, I tried to configure .ssh/config or ~/.gitconfig to use another key, but I failed.

In ecosystem.json:

And now the magic:

$ pm2 deploy ecosystem.json production setup
--> Deploying to production environment
--> on host 10.10.10.10
  ○ hook pre-setup
Enter passphrase for key '/c/Users/alberto.santini/.ssh/my-pm2-ssh-key_rsa':
  ○ running setup
  ○ cloning git@gitlab.com:myuser/foo.git
  ○ full fetch
Enter passphrase for key '/c/Users/alberto.santini/.ssh/my-pm2-ssh-key_rsa':
Cloning into '/home/santini/pm2/foo/source'...
Enter passphrase for key '/c/Users/alberto.santini/.ssh/my-pm2-ssh-key_rsa':
  ○ hook post-setup
  ○ setup complete
--> Success
brapifra commented 2 years ago

I'm also struggling with this. I had to remove the ssh passphrase to be able to use pm2 deploy