title: Jenkins Slave Permission Denied while copying slave.jar
body: <p>I get a permissions denied but don't know why. From my jenkins master I was able to run the following command using ssh-rsa-key</p>
  
  <p><code>scp /var/cache/jenkins/war/WEB-INF/slave.jar jenkins@&lt;my_slave_host&gt;:/var/jenkins/</code></p>
  
  <p><strong>Note:</strong> I did manually create /var/jenkins/ on the my slave host when i saw it didn't exist and made it owned by the jenkins user. My master jenkins is configured to use the jenkins@mySlaveHost using .ssh keys. </p>
  
  <p>Any ideas why I'm getting a permissions denied? What is it trying to do? </p>
  
  <p>Here's the log from master jenkins after clicking [Lauch slave agent] button: </p>
  
  <pre><code>[02/27/15 15:18:01] [SSH] Opening SSH connection to &lt;my_slave_host&gt;:22.
  [02/27/15 15:18:02] [SSH] Authentication successful.
  [02/27/15 15:18:03] [SSH] The remote users environment is:
  BASH=/bin/bash
  BASHOPTS=cmdhist:complete_fullquote:extquote:force_fignore:hostcomplete:interactive_comments:progcomp:promptvars:sourcepath
  BASH_ALIASES=()
  BASH_ARGC=()
  BASH_ARGV=()
  BASH_CMDS=()
  BASH_EXECUTION_STRING=set
  BASH_LINENO=()
  BASH_SOURCE=()
  BASH_VERSINFO=([0]="4" [1]="3" [2]="11" [3]="1" [4]="release" [5]="x86_64-pc-linux-gnu")
  BASH_VERSION='4.3.11(1)-release'
  CATALINA_HOME=/opt/tomcat/current
  DIRSTACK=()
  EUID=107
  GROUPS=()
  HOME=/var/lib/jenkins
  HOSTNAME=*********** REMOVED***********
  HOSTTYPE=x86_64
  IFS=$' \t\n'
  JAVA_HOME=/usr/lib/jvm/java-7-oracle
  LANG=en_US.UTF-8
  LOGNAME=jenkins
  MACHTYPE=x86_64-pc-linux-gnu
  MAIL=/var/mail/jenkins
  OPTERR=1
  OPTIND=1
  OSTYPE=linux-gnu
  PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games
  PIPESTATUS=([0]="0")
  PPID=10592
  PS4='+ '
  PWD=/var/lib/jenkins
  SHELL=/bin/bash
  SHELLOPTS=braceexpand:hashall:interactive-comments
  SHLVL=1
  SSH_CLIENT='10.57.13.32 34436 22'
  SSH_CONNECTION='10.57.13.32 34436 10.57.6.42 22'
  TERM=dumb
  UID=107
  USER=jenkins
  XDG_RUNTIME_DIR=/run/user/107
  XDG_SESSION_ID=42
  _=']'
  [02/27/15 15:18:03] [SSH] Checking java version of java
  [02/27/15 15:18:04] [SSH] java -version returned 1.7.0_76.
  [02/27/15 15:18:04] [SSH] Starting sftp client.
  [02/27/15 15:18:04] [SSH] Copying latest slave.jar...
  hudson.util.IOException2: Could not copy slave.jar into '/var/jenkins' on slave
      at hudson.plugins.sshslaves.SSHLauncher.copySlaveJar(SSHLauncher.java:1019)
      at hudson.plugins.sshslaves.SSHLauncher.access$300(SSHLauncher.java:133)
      at hudson.plugins.sshslaves.SSHLauncher$2.call(SSHLauncher.java:709)
      at hudson.plugins.sshslaves.SSHLauncher$2.call(SSHLauncher.java:696)
      at java.util.concurrent.FutureTask.run(FutureTask.java:266)
      at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
      at java.lang.Thread.run(Thread.java:745)
  Caused by: hudson.util.IOException2: Could not copy slave.jar to '/var/jenkins/slave.jar' on slave
      at hudson.plugins.sshslaves.SSHLauncher.copySlaveJar(SSHLauncher.java:1016)
      ... 7 more
  Caused by: com.trilead.ssh2.SFTPException: Permission denied (SSH_FX_PERMISSION_DENIED: The user does not have sufficient permissions to perform the operation.)
      at com.trilead.ssh2.SFTPv3Client.openFile(SFTPv3Client.java:1201)
      at com.trilead.ssh2.SFTPv3Client.createFile(SFTPv3Client.java:1074)
      at com.trilead.ssh2.SFTPv3Client.createFile(SFTPv3Client.java:1055)
      at hudson.plugins.sshslaves.SFTPClient.writeToFile(SFTPClient.java:93)
      at hudson.plugins.sshslaves.SSHLauncher.copySlaveJar(SSHLauncher.java:1008)
      ... 7 more
  [02/27/15 15:18:04] Launch failed - cleaning up connection
  [02/27/15 15:18:04] [SSH] Connection closed.
  </code></pre>
  
  <p>Edit: 
  Here's /var/jenkins on the slave: </p>
  
  <pre><code>$ ls -al
  total 436
  drwxr-xr-x  2 jenkins jenkins     22 Feb 27 15:17 .
  drwxr-xr-x 14 root    root      4096 Feb 27 15:12 ..
  -rw-r--r--  1 jenkins jenkins 439584 Feb 27 15:17 slave.jar
  </code></pre>
  
  <p>As for SFTP, I do not think it is enabled, can you point me to any docs that says SFTP is a pre-requisite for a slave? All the pages I've seen do not mention SFTP. </p>