Sample Header Ad - 728x90

Permissions Issue creating folder on remote host with Jenkins

0 votes
1 answer
1909 views
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 ubuntu@x.x.x.x 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 ubuntu 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
### Question **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.
Asked by Programster (2289 rep)
Oct 13, 2021, 11:26 AM
Last activity: Jul 22, 2025, 12:10 AM