Set uploads folder as the default
When SFTP users connect, you may want them to start in the /uploads
folder.
This can be set on SFTP clients like FileZilla. Go to Advanced > Default remote directory, and enter in uploads
It's not be practical to ask every user to do this from their end. So it might be easier to just set this on the server side.
Targeting whole server for default directory
Edit the sshd_config
file:
sudo nano /etc/ssh/sshd_config
Scroll toward the bottom, and change the following line:
ForceCommand internal-sftp
To:
ForceCommand internal-sftp -d /uploads
Save (ctrl-o
) and quit (ctrl-x
)
The -d
flag sets the user's starting directory. It does not have any impact on their chroot
directory, so they can
still traverse up a level to get to their local
folder.
Restart sshd to apply the changes:
service sshd restart
This change will apply to all SFTP users, since the modified line is inside Match group sftponly
.
Connect using FileZilla, and you should already be inside the /uploads
directory.
Targeting individual users for default directory
Edit sshd_config
:
sudo nano /etc/ssh/sshd_config
Instead of modifying the ForceCommand
line in the Match group sftponly
block, you will add another configuration
block above the Match group sftponly
block.
IMPORTANT: The following block must go above the Match group sftponly
block in order to take effect.
This block will read as follows:
Match user username1,username2
ForceCommand internal-sftp -d /uploads
A single Match user
block can be used to configure multiple users by adding a comma between each username.
Note: that there is no space between the comma and the next username.
Save (ctrl-o
) and quit (ctrl-x
)
Then, restart the sshd to apply the changes:
sudo service sshd restart