Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

How to deploy through proxy server passing private key

bastien October 30, 2018

I am deploying through pm2 and a proxy server (BitbucketPipeline -> authentication to B -> deploying to C)

Here is my pipeline

image: node:8.11.2

pipelines:
branches:
stage/development:
- step:
caches:
- node
script:
- npm run test
- mkdir -p ~/.ssh
- cat bitbucket-ssh-config >> ~/.ssh/config
- npm install -g pm2
- npm run deploy-development # triggers pm2 deployment

Here  is my bitbucket-ssh-config :

Host SMTHG
User USER
Hostname C
IdentityFile ~/.ssh/id_rsa
ProxyCommand ssh -i ~/.ssh/id_rsa -W %h:%p USER@B 

It seems to work perfectly but i get the following error :

Warning: Identity file /root/.ssh/id_rsa not accessible: No such file or directory. 

I could generate my own private key but I prefer to use the default one, how can I do ? 

 

EDIT : 

I finally tried to use "/opt/atlassian/pipelines/agent/ssh/id_rsa"

I was successfully connecting to the server "B" directly but getting an error after:

ssh_exchange_identification: Connection closed by remote host

So I tried to re-generate the key pair. And I append it to ".ssh/authorized_keys" of both servers (B & C) and now it doesn't work anymore and i can't even ssh to the server B ?

 

EDIT 2 :

I finally tried with a custom key pair by adding this script step 

- (umask  077 ; echo $DEV_PIPELINE_KEY | base64 --decode > ~/.ssh/id_rsa)

It suvccessfully authenticate through the gateway but then it's blocked and I don't get why as I use th exact same way from my computer

 

Warning: Permanently added the RSA host key for IP address 'xxxxxx' to the list of known hosts.
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: SSH2_MSG_SERVICE_REQUEST sent
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey
debug1: Next authentication method: publickey
debug1: Trying private key: /root/.ssh/id_rsa
debug1: Authentication succeeded (publickey).
Authenticated to xxxxx.com ([xxxxxxxx]:22).
debug1: channel_connect_stdio_fwd xxxxxx:22
debug1: channel 0: new [stdio-forward]
debug1: getpeername failed: Bad file descriptor
debug1: Requesting no-more-sessions@openssh.com
debug1: Entering interactive session.
debug1: client_input_global_request: rtype hostkeys-00@openssh.com want_reply 0
Host key verification failed.
debug1: channel 0: free: direct-tcpip: listening port 0 for xxxxxx port 22, connect from 127.0.0.1 port 65535 to UNKNOWN port 65536, nchannels 1
debug1: fd 0 clearing O_NONBLOCK
debug1: fd 1 clearing O_NONBLOCK
debug1: Killed by signal 1.

 

0 answers

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events