sftp: remote open("/file"): Permission denied
I login correctly to container with the command sftp -P 2222 user@ip_container
To sftp shell i get this error:
sftp> put file.sh
Uploading file.sh to /file.sh
remote open("/file.sh"): Permission denied
I have run the container with docker-compose:
sftp:
image: atmoz/sftp
volumes:
- /host/sftpdata:/home/sftp/share
ports:
- "2222:22"
command: sftp:password:1001
About this issue
- Original URL
- State: closed
- Created 9 years ago
- Reactions: 2
- Comments: 24 (2 by maintainers)
Here is a way to configure automatically the creation & permissions for a
share
folder: it will create ashare
folder for every users with a home folder and change ownership to the proper user.docker-compose.yml
init.sh
I ran into this also. For me, it was failing to pass in the subdirectory name as an argument to the container COMMAND.
In the above examples I see
malnes:randompassword:1001
Which does not reference the subdirectory.Here’s the line which sorted out the permissions issue for me.
command: foo:pass:::upload
I’m using a shared volume, so have omitted the group identification mapping.
For reference, here’s my volume line from the sftp service declaration:
I will allow myself to note that part about permissions is yet to be clarified in main README.md. From perspective of semi-noob as a devops it easy to fail on that front I would suggest modyfing following paragraph of README.md:
Into:
With sentence like that it will save a noob or two out there. 😉
Each user is jailed in their home directory (for security). That means root is owning the home directory, and the user can not modify it’s content. The user can only do changes inside sub-directories.
You have to create a directory (i.e. mount a volume) inside the user’s home directory, and then you can upload files there. In your case, this will be the “share” directory.
This is the nature of file permissions and volumes. They have to match if you want it to work as you expect. I will have a closer look at this challenge soon, and will add more to the documentation, so fewer people fall into this pit.
I’m having the same problem. I find the documentation a bit lacking. Why is this not enough:
Logging into the SFTP account, the user is not allowed to put files in either
/
or/share
. Shouldn’t this work out of the box?Should the
/home/SFTP/malnes/share
folder be created on host? (I have, with666
permissions.)Intuition fails me here.
None of the above worked for me. Here’s what I had to do:
The gist of it is that
data
is empty, sofolder
is created inside it, with the appropriate permissions, when the service is started. Here’s how I was trying to do it:Ensuring the UID and GID matched did nothing for me in this case.
To anyone who is still experience the problem. Provided that the directory or volume exists. I modified the command line from the docker-compose example with foo as username.
command: foo:pass:1001:::upload
No additional permissions or scripts required to run (other than ensuring that Docker has got access on Mac etc).
so the Docker version of it on cli.
How to resovle this issue under Windows.
FWIW I was able to get this to work just by making the
/host/upload
folder owned by the same uid as the docker user. In my case it was 1001.I am completely stuck on this issue and I have tried everything in this thread.
Docker compose config:
just as @2hoursleep suggested.
In my code, I use:
which produces the logs:
However, it’s not true!! if I docker exec into the container:
That directory definitely exists
I have also tried
sftp.cd
to change to/home/testuser/upload
but same problemFor those still having issues:
1- Get UID of user with:
$ id -u
2- Use correct path for home dir when mounting volume + use previous UID:
For $USER:pass:$UID volume => /your/whatever/path:/home/$USER/upload