title: Get Jenkins to SSH into server and pull from git - post build
body: <p>I have a Jenkins instance and I am trying to create a continuous integration workflow. I am struggling to get jenkins to get the code onto the production server.</p>
  
  <p>Here is what I'm trying to do:</p>
  
  <ol>
  <li>on push to master branch (bitbucket), run build (working)</li>
  <li>after build passed, SSH into production server (working)</li>
  <li>on production server, git pull master to update the project (not working)</li>
  </ol>
  
  <p>I seem to be having the following problem:</p>
  
  <ol>
  <li>jenkins SSHs into the prod server with user <code>deploy</code>.</li>
  <li>Although <code>deploy</code> has <code>id_rsa</code> keys in <code>~/.ssh</code>, with the contents of <code>id_rsa.pub</code> in bitbucket's 'deployment keys' setting for the repo, I get a <code>Permission denied (publickey).</code> error when I run <code>git pull</code> or <code>git clone</code>.</li>
  </ol>
  
  <p>So this has left me confused and I'm not sure where I'm going wrong.. For me it could be one or many of these things:</p>
  
  <ol>
  <li>Why aren't deploy's ssh credentials being picked up automatically?</li>
  <li>Should the prod server have its own SSH credentials? I think so.</li>
  <li>Does this process seem sensible? It did to me until I ran into this trouble...</li>
  </ol>
  
  <p>Any ideas, advice or alternative routes are greatly appreciated.</p>
  
  <hr>
  
  <p><strong>UPDATE</strong></p>
  
  <p>When running this myself as the same user that jenkins uses, when I run <code>git clone ...</code>, I get prompted for the passphrase for id_rsa. This must be where jenkins is tripping up as it cannot decode id_rsa. I will see if I can generate an ssh key that doesnt prompt for a passphrase</p>
  
  <p><strong>UPDATE 2</strong></p>
  
  <p>I generated an ssh key for the production server that did not require a passphrase to use, and this worked fine.</p>