I'm having an issue with using Jenkins to create a folder on a remote host.

The remote host in this case is a stock Ubuntu 20.04 AMI EC2 server with the default ubuntu user.

I am connecting with the ubuntu user to the remote server with the code below:

sshagent(credentials : [branchConfig.SSH_CREDENTIALS_NAME]) {
    sh 'ssh -o StrictHostKeyChecking=no ' + branchConfig.SSH_USER + '@' + branchConfig.DOCKER_HOST + ' "echo \"running whoami\" && whoami && echo \"running groups\" && groups && install --directory --mode 0755 --owner ' + branchConfig.SSH_USER + ' --group ' + branchConfig.SSH_USER + ' ~/importengine"'

This outputs the following error:

+ ssh -o StrictHostKeyChecking=no [email protected] echo running whoami && whoami && echo running groups && groups && install --directory --mode 0755 --owner ubuntu --group ubuntu ~/importengine
Warning: Permanently added 'x.x.x.x' (ECDSA) to the list of known hosts.

running whoami
running groups
ubuntu docker
install: cannot change owner and permissions of ���/home/ubuntu/importengine���: Operation not permitted

I can see that the folder gets created, but it has the following permissons:

drwxr-xr-x 2 root   root   4.0K Oct 13 11:12 importengine

If I delete the folder and run the following command (when logged in as ubuntu):

install --directory --mode 0755 --owner ubuntu --group ubuntu ~/importengine

...then the folder gets created with the following permissions:

drwxr-xr-x 2 ubuntu ubuntu 4.0K Oct 13 11:24 importengine


Why is the folder getting created as owned by root in the first place? After all, I can clearly see that whoami outputs as ubuntu, and not root in the error output so it should be creating the folder as if the ubuntu user.

  • Look into man install. --owner is super-user only. Also, according to synopsis, --directory should be the last flag.
    – Panki
    Commented Oct 13, 2021 at 12:53
  • I get the same thing if I just run a mkdir ~/importengine and only switched to using install when that didn't work. Any ideas why the folder is getting created as owned by root? Commented Oct 13, 2021 at 13:08
  • I just tried this with install --directory --mode 0755 --owner panki --group panki ~/test, can not reproduce (Debian Buster).
    – Panki
    Commented Oct 13, 2021 at 13:20
  • Perhaps the folder in question already exists before running the install command?
    – jayhendren
    Commented Oct 13, 2021 at 20:11
  • @jayhendren no, i've been manually deleting it an having this issue every time I retry with diferent attempts. Commented Oct 14, 2021 at 14:18

1 Answer 1


In the end, I was unable to figure out what was causing the issue so I had to work around it by creating the folder of files locally and then scp that across, which did the trick. E.g.

sshagent(credentials : [SSH_CREDENTIALS_NAME]) {
    // copy over the .env file in a subfolder. Have to use scp because of strange permissions issue.
    sh 'mkdir -p ~/importengine && cp ' + ENV_FILEPATH + ' ~/importengine/.env'
    sh 'scp -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -r ~/importengine ' + SSH_USER + '@' + DOCKER_HOST + ':~/.'

Side Note

This issue really confused my colleagues and me. I and figure it must be Jenkins specific somehow. I was not able to reproduce this issue by running any of the steps manually from my Linux machine (e.g. outside of Jenkins).

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .