Score:0

SFTP jail root user can login but not upload, or upload and not login

cn flag

I have seen this asked before, but none of the solutions works for me. I managed to make sftp login for a user, but I didn't manage to give the user permission to upload.

As far as I can understand, I am using OpenSSH's SFTP subsystem (ftp over ssh, port 22, and not a separate FTP server software):

$ ps -ef | grep sftp-server
otheruser   61324   32347  0 14:57 pts/0    00:00:00 grep --color=auto sftp-server

This is the sshd_config:

Include /etc/ssh/sshd_config.d/*.conf
PasswordAuthentication yes
ChallengeResponseAuthentication no
UsePAM yes
X11Forwarding yes
PrintMotd no
AcceptEnv LANG LC_*
Subsystem       sftp    internal-sftp
Match User user1
   ChrootDirectory /sftp_files/uploads

folder permissions:

$ ls -ld /sftp_files/uploads
drwxr-xr-x 2 root root 4096 Jan 10 14:10 /sftp_files/uploads

$ ls -ld /sftp_files
drwxr-xr-x 3 root root 4096 Jan  9 15:15 /sftp_files

$ id user1
uid=1001(user1) gid=1001(user1) groups=1001(user1),0(root),125(ftp)

with the above permissions (755 on /sftp_files/uploads), I manage to login, read and download files. but when I try to upload I am getting Permission denied. Error code: 3

If I set:

sudo chmod 775 /sftp_files/uploads

While I am already logged in, I manage to upload files, but after logout, I am not able to login again. The error is:

fatal: bad ownership or modes for chroot directory "/sftp_files/uploads"

Is there any way to allow the user to upload the files?

Score:0
cn flag

I found a solution. It is quite simple really.. Using the same configuration as I posted above, I just added another folder below uploads and gave it 777 permissions.

cd /sftp_files/uploads
mkdir whatever
chmod 777 whatever

Then after login, user can upload files inside the folder whatever.

I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.