title: Jenkins Pipeline: SCP commnd not working when executed through pipeline, same works fine through GIT Bash
body: <p>I have two ubuntu aws instance and below are following details</p>
  <ol>
  <li>DevServer: 172.31.29.201</li>
  <li>QAServer: 172.31.30.52</li>
  </ol>
  <p>I establish a passwordless SSH between two machine bu generating ssh-keygen in DevServer and copied it to QAServer using ssh-copy-id ubuntu@172.31.30.52 [ubuntu is username and 172.31.30.52 is private ip address of the QAServer)</p>
  <p>I'm able to successfully make a SSH connection to the QAServer from DevServer without any issue</p>
  <p><a href="https://i.stack.imgur.com/h6yzB.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/h6yzB.png" alt="enter image description here" /></a></p>
  <p>Even scp command to transfer the .war file to the QAServer tomcat8/webapps is successful. File qaapp.war is transferred to the tomcat8/webapps/ folder</p>
  <pre><code>ubuntu@DevServer:~$ scp -o StrictHostKeyChecking=no /var/lib/jenkins/workspace/Pipeline_dev_01/webapp/target/webapp.war ubuntu@172.31.30.52:/var/lib/tomcat8/webapps/qaapp.war
  webapp.war
  
  100% 3125     3.8MB/s   00:00
  
  ubuntu@DevServer:~$
  </code></pre>
  <p>Pipeline code:</p>
  <pre><code>node('built-in') 
  {
      stage('ContinousDownload') 
      {
          git 'https://github.com/rasivana/maven.git'
      }
      stage('ContinousBuild') 
      {
          sh 'mvn package'
      }
      stage('ContinousDeployment')
      {
          sh 'scp -v -o StrictHostKeyChecking=no /var/lib/jenkins/workspace/Pipeline_dev_01/webapp/target/webapp.war ubuntu@172.31.30.52:/var/lib/tomcat8/webapps/qaapp.war'
      }
  }
  </code></pre>
  <p>We get following error</p>
  <p><a href="https://i.stack.imgur.com/1psfh.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/1psfh.png" alt="enter image description here" /></a></p>
  <p>Complete logs:</p>
  <pre><code>+ scp -v -o StrictHostKeyChecking=no /var/lib/jenkins/workspace/Pipeline_dev_01/webapp/target/webapp.war ubuntu@172.31.30.52:/var/lib/tomcat8/webapps/qaapp.war
  Executing: program /usr/bin/ssh host 172.31.30.52, user ubuntu, command scp -v -t /var/lib/tomcat8/webapps/qaapp.war
  OpenSSH_7.6p1 Ubuntu-4ubuntu0.5, OpenSSL 1.0.2n  7 Dec 2017
  debug1: Reading configuration data /etc/ssh/ssh_config
  debug1: /etc/ssh/ssh_config line 19: Applying options for *
  debug1: Connecting to 172.31.30.52 [172.31.30.52] port 22.
  debug1: Connection established.
  debug1: key_load_public: No such file or directory
  debug1: identity file /var/lib/jenkins/.ssh/id_rsa type -1
  debug1: key_load_public: No such file or directory
  debug1: identity file /var/lib/jenkins/.ssh/id_rsa-cert type -1
  debug1: key_load_public: No such file or directory
  debug1: identity file /var/lib/jenkins/.ssh/id_dsa type -1
  debug1: key_load_public: No such file or directory
  debug1: identity file /var/lib/jenkins/.ssh/id_dsa-cert type -1
  debug1: key_load_public: No such file or directory
  debug1: identity file /var/lib/jenkins/.ssh/id_ecdsa type -1
  debug1: key_load_public: No such file or directory
  debug1: identity file /var/lib/jenkins/.ssh/id_ecdsa-cert type -1
  debug1: key_load_public: No such file or directory
  debug1: identity file /var/lib/jenkins/.ssh/id_ed25519 type -1
  debug1: key_load_public: No such file or directory
  debug1: identity file /var/lib/jenkins/.ssh/id_ed25519-cert type -1
  debug1: Local version string SSH-2.0-OpenSSH_7.6p1 Ubuntu-4ubuntu0.5
  debug1: Remote protocol version 2.0, remote software version OpenSSH_7.6p1 Ubuntu-4ubuntu0.5
  debug1: match: OpenSSH_7.6p1 Ubuntu-4ubuntu0.5 pat OpenSSH* compat 0x04000000
  debug1: Authenticating to 172.31.30.52:22 as 'ubuntu'
  debug1: SSH2_MSG_KEXINIT sent
  debug1: SSH2_MSG_KEXINIT received
  debug1: kex: algorithm: curve25519-sha256
  debug1: kex: host key algorithm: ecdsa-sha2-nistp256
  debug1: kex: server-&gt;client cipher: chacha20-poly1305@openssh.com MAC: &lt;implicit&gt; compression: none
  debug1: kex: client-&gt;server cipher: chacha20-poly1305@openssh.com MAC: &lt;implicit&gt; compression: none
  debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
  debug1: Server host key: ecdsa-sha2-nistp256 SHA256:428mcfQF4kAq6DMmrP68kF6nz18rUZlKA3DjtsTcrpk
  debug1: Host '172.31.30.52' is known and matches the ECDSA host key.
  debug1: Found key in /var/lib/jenkins/.ssh/known_hosts:1
  debug1: rekey after 134217728 blocks
  debug1: SSH2_MSG_NEWKEYS sent
  debug1: expecting SSH2_MSG_NEWKEYS
  debug1: SSH2_MSG_NEWKEYS received
  debug1: rekey after 134217728 blocks
  debug1: SSH2_MSG_EXT_INFO received
  debug1: kex_input_ext_info: server-sig-algs=&lt;ssh-ed25519,ssh-rsa,rsa-sha2-256,rsa-sha2-512,ssh-dss,ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521&gt;
  debug1: SSH2_MSG_SERVICE_ACCEPT received
  debug1: Authentications that can continue: publickey,password
  debug1: Next authentication method: publickey
  debug1: Trying private key: /var/lib/jenkins/.ssh/id_rsa
  Load key &quot;/var/lib/jenkins/.ssh/id_rsa&quot;: Permission denied
  debug1: Trying private key: /var/lib/jenkins/.ssh/id_dsa
  debug1: Trying private key: /var/lib/jenkins/.ssh/id_ecdsa
  debug1: Trying private key: /var/lib/jenkins/.ssh/id_ed25519
  debug1: Next authentication method: password
  debug1: read_passphrase: can't open /dev/tty: No such device or address
  debug1: Authentications that can continue: publickey,password
  Permission denied, please try again.
  debug1: read_passphrase: can't open /dev/tty: No such device or address
  debug1: Authentications that can continue: publickey,password
  Permission denied, please try again.
  debug1: read_passphrase: can't open /dev/tty: No such device or address
  debug1: Authentications that can continue: publickey,password
  debug1: No more authentication methods to try.
  ubuntu@172.31.30.52: Permission denied (publickey,password).
  lost connection
  </code></pre>
  <p>Same with cmd prompt scp works file and file gets transferred. Thought first time it asked for ubuntu user passowrd. Pasting below for analysis</p>
  <pre><code>ubuntu@DevServer:~$ scp -v -o StrictHostKeyChecking=no /var/lib/jenkins/workspace/Pipeline_dev_01/webapp/target/webapp.war ubuntu@172.31.30.52:/var/lib/tomcat8/webapps/qaapp.war
  Executing: program /usr/bin/ssh host 172.31.30.52, user ubuntu, command scp -v -t /var/lib/tomcat8/webapps/qaapp.war
  OpenSSH_7.6p1 Ubuntu-4ubuntu0.5, OpenSSL 1.0.2n  7 Dec 2017
  debug1: Reading configuration data /etc/ssh/ssh_config
  debug1: /etc/ssh/ssh_config line 19: Applying options for *
  debug1: Connecting to 172.31.30.52 [172.31.30.52] port 22.
  debug1: Connection established.
  debug1: identity file /home/ubuntu/.ssh/id_rsa type 0
  debug1: key_load_public: No such file or directory
  debug1: identity file /home/ubuntu/.ssh/id_rsa-cert type -1
  debug1: key_load_public: No such file or directory
  debug1: identity file /home/ubuntu/.ssh/id_dsa type -1
  debug1: key_load_public: No such file or directory
  debug1: identity file /home/ubuntu/.ssh/id_dsa-cert type -1
  debug1: key_load_public: No such file or directory
  debug1: identity file /home/ubuntu/.ssh/id_ecdsa type -1
  debug1: key_load_public: No such file or directory
  debug1: identity file /home/ubuntu/.ssh/id_ecdsa-cert type -1
  debug1: key_load_public: No such file or directory
  debug1: identity file /home/ubuntu/.ssh/id_ed25519 type -1
  debug1: key_load_public: No such file or directory
  debug1: identity file /home/ubuntu/.ssh/id_ed25519-cert type -1
  debug1: Local version string SSH-2.0-OpenSSH_7.6p1 Ubuntu-4ubuntu0.5
  debug1: Remote protocol version 2.0, remote software version OpenSSH_7.6p1 Ubuntu-4ubuntu0.5
  debug1: match: OpenSSH_7.6p1 Ubuntu-4ubuntu0.5 pat OpenSSH* compat 0x04000000
  debug1: Authenticating to 172.31.30.52:22 as 'ubuntu'
  debug1: SSH2_MSG_KEXINIT sent
  debug1: SSH2_MSG_KEXINIT received
  debug1: kex: algorithm: curve25519-sha256
  debug1: kex: host key algorithm: ecdsa-sha2-nistp256
  debug1: kex: server-&gt;client cipher: chacha20-poly1305@openssh.com MAC: &lt;implicit&gt; compression: none
  debug1: kex: client-&gt;server cipher: chacha20-poly1305@openssh.com MAC: &lt;implicit&gt; compression: none
  debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
  debug1: Server host key: ecdsa-sha2-nistp256 SHA256:428mcfQF4kAq6DMmrP68kF6nz18rUZlKA3DjtsTcrpk
  debug1: Host '172.31.30.52' is known and matches the ECDSA host key.
  debug1: Found key in /home/ubuntu/.ssh/known_hosts:1
  debug1: rekey after 134217728 blocks
  debug1: SSH2_MSG_NEWKEYS sent
  debug1: expecting SSH2_MSG_NEWKEYS
  debug1: SSH2_MSG_NEWKEYS received
  debug1: rekey after 134217728 blocks
  debug1: SSH2_MSG_EXT_INFO received
  debug1: kex_input_ext_info: server-sig-algs=&lt;ssh-ed25519,ssh-rsa,rsa-sha2-256,rsa-sha2-512,ssh-dss,ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521&gt;
  debug1: SSH2_MSG_SERVICE_ACCEPT received
  debug1: Authentications that can continue: publickey,password
  debug1: Next authentication method: publickey
  debug1: Offering public key: RSA SHA256:UHBTYkIj/Zm87NrPLFNOwz8/1bzOtM9ahxtdwcCfKIA /home/ubuntu/.ssh/id_rsa
  debug1: Server accepts key: pkalg rsa-sha2-512 blen 279
  debug1: Authentication succeeded (publickey).
  Authenticated to 172.31.30.52 ([172.31.30.52]:22).
  debug1: channel 0: new [client-session]
  debug1: Requesting no-more-sessions@openssh.com
  debug1: Entering interactive session.
  debug1: pledge: network
  debug1: client_input_global_request: rtype hostkeys-00@openssh.com want_reply 0
  debug1: Sending environment.
  debug1: Sending env LANG = C.UTF-8
  debug1: Sending command: scp -v -t /var/lib/tomcat8/webapps/qaapp.war
  Sending file modes: C0644 3125 webapp.war
  Sink: C0644 3125 webapp.war
  webapp.war                                                                                                                                                 100% 3125     4.2MB/s   00:00
  debug1: client_input_channel_req: channel 0 rtype exit-status reply 0
  debug1: channel 0: free: client-session, nchannels 1
  debug1: fd 0 clearing O_NONBLOCK
  debug1: fd 1 clearing O_NONBLOCK
  Transferred: sent 5972, received 2648 bytes, in 0.5 seconds
  Bytes per second: sent 12812.5, received 5681.1
  debug1: Exit status 0
  ubuntu@DevServer:~$
  </code></pre>
  <p>Why same command when executed through GIT Bash works without any error, and command executed through jenkins pipe line execution is not working?</p>
  <p>Attaching a text comparison between the Jenkins execution and GIT bash execution image file.</p>
  <p><a href="https://i.stack.imgur.com/NKUo2.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/NKUo2.png" alt="enter image description here" /></a></p>