Điểm:0

SFTP users won't be able to connect if set fstab file_mode, dir_mode other than 0755

lá cờ pk

I'm setting up an SFTP server on Azure VM running Ubuntu Server 20.04. I'm not using local disks to store SFTP files but instead use Azure File Share and mount it via SMB 3.1.1 on fstab.

This is my fstab config

//mystorage.file.core.windows.net/sftp-storage /mount/mystorage/sftp-storage cifs nofail,credentials=/etc/smbcredentials/sftpstorage.cred,serverino,gid=1002,file_mode=0755,dir_mode=0755 0 0

Inside Azure File Share, there are many folders for each SFTP user. E.g. user1, user2 where both users are put in the same secondary group called sftpusers with gid=1002

This is when I run id user1

uid=1001(user1) gid=1001(user1) groups=1001(user1),1002(sftpusers)

This is when I run id user2

uid=1002(user2) gid=1003(user2) groups=1003(user2),1002(sftpusers)

This is the bottom of my /etc/ssh/sshd_config file

Match User user1
    ForceCommand internal-sftp
    PasswordAuthentication yes
    ChrootDirectory /mount/mystorage/sftp-storage/user1
    PermitTunnel no
    AllowAgentForwarding no
    AllowTcpForwarding no
    X11Forwarding no

Match User user2
    ForceCommand internal-sftp
    PasswordAuthentication yes
    ChrootDirectory /mount/mystorage/sftp-storage/user2
    PermitTunnel no
    AllowAgentForwarding no
    AllowTcpForwarding no
    X11Forwarding no

With above configs, both users are able to connect and chrooted to their own directories. However, none of them are able to upload files or create a directory. FileZilla would say "permission denied". Only downloading can be done.

I then thought that this was caused by file_mode=0755,dir_mode=0755 in fstab config, so I changed it to file_mode=0775,dir_mode=0775. I unmounted and re-mounted it again but this time none of the users were able to connect. I found this thread which seems very similar to my problem and tried the workaround but didn't work for me. Still can't connect.

I also tried file_mode=0777,dir_mode=0777 but didn't work either. The only permission that would allow users to connect is 0755.

When I run ls -l /mount/mystorage/sftp-storage/ this is what I got

drwxr-xr-x 2 root sftpusers 0 Sep 21 12:01 user1
drwxr-xr-x 2 root sftpusers 0 Sep 21 12:01 user2

Please guide me how to make this work. Here are what I am trying to achieve:

  • Having multiple SFTP users chrooted to their own directories
  • All SFTP users must be able to read, write, delete files and create, delete directories (under their own dir)
  • Have configs that are easy to maintain and easy to add more users in the future

I'm suspecting that this is caused by misconfigurations in permission somewhere.

Any suggestions are welcomed, thanks.

Đăng câu trả lời

Hầu hết mọi người không hiểu rằng việc đặt nhiều câu hỏi sẽ mở ra cơ hội học hỏi và cải thiện mối quan hệ giữa các cá nhân. Ví dụ, trong các nghiên cứu của Alison, mặc dù mọi người có thể nhớ chính xác có bao nhiêu câu hỏi đã được đặt ra trong các cuộc trò chuyện của họ, nhưng họ không trực giác nhận ra mối liên hệ giữa câu hỏi và sự yêu thích. Qua bốn nghiên cứu, trong đó những người tham gia tự tham gia vào các cuộc trò chuyện hoặc đọc bản ghi lại các cuộc trò chuyện của người khác, mọi người có xu hướng không nhận ra rằng việc đặt câu hỏi sẽ ảnh hưởng—hoặc đã ảnh hưởng—mức độ thân thiện giữa những người đối thoại.