How to change SFTP default directory

Unfortunately I don't have enough reputation to comment because all I wanted to do is stress how important the comment by Richard Fairhurst is and how it should be added to the "official answer". I have seen people here and elsewhere having trouble setting the user home directory or having the user home directory as a "default directory". That's just because in a chroot environment the root directory is not the / any more. Meaning any other path should be relative to the new root path. Ex:

if you chroot to /home and want the default directory to be /home/default you should set the user home directory to /default. Not /home because /home will be the new /.

If you really need to keep the user home directory in /home/user but wish to have a default directory for sftp sessions, you can use the -d parameter for internal-sftp. Like in this example:

Subsystem sftp internal-sftp
Match Group sftpusers
    ChrootDirectory /mnt/sftp
    ForceCommand internal-sftp -d /default

/default being a directory inside /mnt/sftp. Notice that path here is again relative to the new root.


Have a look at this article which shows how to use sshd's ChrootDirectory to force all members of a particular group into a common directory root. You may be able to modify it to meet your requirements.


Perhaps there is a way to achieve what you want but as far as I know, sftp is operated over ssh so not so sure how to do that with ssh for every user.

However, one way to get around what you want to do is that you can update the user data to log in to certain directory as follows. This will w

$ sudo usermod -d [certain path that you want to direct] username

Tags:

Sftp

Proftpd