Page 1 of 1

Set permission to SFTP users

Posted: 02 Feb 2021, 07:11
by fabiobiscia
Hi, I wanna customize some user preferences. I would like set that ftp users can’t navigate the root of a given folder. I tried to modify the sshd_config file in /etc/ssh and in a certain way it worked. The only problem is that on every reboot the /home/ftpuser folder must be owner changed from ftpuser to root in order to make accessible the ftp account, also permissions must be set with chmod. I don’t know why is necessary this procedure but it works. The main problem is that I wrote a little script to do this on every reboot but it doesn’t work (same on crontab); the same line of code from ssh session makes everything working. How it’s possible? I was logged with root obviously. So, How can I manage ftp user accessibility?

These are the lines modified from sshd_config file

Code: Select all

Subsystem sftp internal-sftp

Match User ftpuser
    ChrootDirectory %h
    X11Forwarding no
    AllowTcpForwarding no
    ForceCommand internal-sftp
After that I restarted ssh services

This is the startup script placed into /etc/init.d (with symlink to sc.d)

Code: Select all

#!/bin/bash
chown root:root /home/ftpuser
chmod 755 /home/ftpuser

Re: Set permission to SFTP users

Posted: 02 Feb 2021, 14:55
by RyanYang
Hello,
You can use the touch command in the /etc/sc.d directory to create an empty file with the same name as your script.
sh.png
Note: script.sh refers to your script, you need to replace it with your script name.

Re: Set permission to SFTP users

Posted: 02 Feb 2021, 16:15
by fabiobiscia
Unfortunately this doesn’t work, the same line of code executed from terminal works but placed into /etc/init.d and a text file into /etc/sc.d doesn’t works. Chown requires special privileges? Sudo command doesn’t work.

Re: Set permission to SFTP users

Posted: 02 Feb 2021, 17:57
by RyanYang
Hi,
Is the file you created in /etc/sc.d empty?
Is the name of the empty file the same as the name of the script you put in /etc/init.d?
You do not need to use the Sudo command after logging in as root.
To log in to other users, you can try to add other users to the admin group and enable user SSH login in the advanced settings of the edit user

Re: Set permission to SFTP users

Posted: 02 Feb 2021, 18:27
by fabiobiscia
I have followed your steps but no way to make it works. But there is a news. After a completely fresh install of SO the same line of code works in crontab. How is it possible? It’s a good thing run the script every X minutes?

Re: Set permission to SFTP users

Posted: 03 Feb 2021, 09:28
by RyanYang
Hello,
If you cannot use this method, there is no way for the time being.
Did you use crontab -e to reset it after reinstalling the system?
If so, the script will always run unless the device is restarted. Maybe you can set the rest time in the script.
This effect depends on your script. For example, if it is a script that is copied automatically and repeatedly, the usage of the hard disk will increase.

Re: Set permission to SFTP users

Posted: 03 Feb 2021, 16:12
by fabiobiscia
Okok, I understand. I will try alternative solutions