[GH-ISSUE #2400] Restrict SFTP access to user's $HOME directory (or use blacklist) #1600

Closed
opened 2026-05-05 08:15:25 -06:00 by gitea-mirror · 5 comments
Owner

Originally created by @fevangelou on GitHub (Feb 13, 2019).
Original GitHub issue: https://github.com/netblue30/firejail/issues/2400

First off, thank you for such a great piece of software.

On a multi-tenant server setup using Ubuntu 18.04, I have managed to restrict SSH access for users so they are not allowed to see certain folder (e.g. /backup, /etc/nginx, /etc/php and so on) by swapping their shell with "/usr/bin/firejail" upon user creation. Aside the aforementioned folders (which are listed in my custom /etc/firejail/disable-common.local), these users cannot navigate to other /home/* folders and processes like top/htop are nicely restricted to these users' processes. So all good on the SSH front.

However, for practical reasons, users must have SFTP access as well. I've found no clue so far as to how/if it's possible to restrict SFTP access similarly to SSH access.

In other words, would it be possible to always enforce /usr/lib/sftp-server or /usr/lib/openssh/sftp-server (whichever is mentioned in /etc/ssh/sshd_config at "Subsystem sftp...") to run via Firejail?

Thanks in advance.

Originally created by @fevangelou on GitHub (Feb 13, 2019). Original GitHub issue: https://github.com/netblue30/firejail/issues/2400 First off, thank you for such a great piece of software. On a multi-tenant server setup using Ubuntu 18.04, I have managed to restrict SSH access for users so they are not allowed to see certain folder (e.g. /backup, /etc/nginx, /etc/php and so on) by swapping their shell with "/usr/bin/firejail" upon user creation. Aside the aforementioned folders (which are listed in my custom /etc/firejail/disable-common.local), these users cannot navigate to other /home/* folders and processes like top/htop are nicely restricted to these users' processes. So all good on the SSH front. However, for practical reasons, users must have SFTP access as well. I've found no clue so far as to how/if it's possible to restrict SFTP access similarly to SSH access. In other words, would it be possible to always enforce /usr/lib/sftp-server or /usr/lib/openssh/sftp-server (whichever is mentioned in /etc/ssh/sshd_config at "Subsystem sftp...") to run via Firejail? Thanks in advance.
gitea-mirror 2026-05-05 08:15:25 -06:00
Author
Owner

@chiraag-nataraj commented on GitHub (Feb 17, 2019):

Why not just set the option to firejail /usr/lib/sftp-server or whatever in /etc/ssh/sshd_config? The other alternative (if you're spawning the server as a system service) would be to edit the init script or systemd unit file to launch the program via firejail.

<!-- gh-comment-id:464457907 --> @chiraag-nataraj commented on GitHub (Feb 17, 2019): Why not just set the option to `firejail /usr/lib/sftp-server` or whatever in `/etc/ssh/sshd_config`? The other alternative (if you're spawning the server as a system service) would be to edit the init script or systemd unit file to launch the program via `firejail`.
Author
Owner

@Gimly86 commented on GitHub (Mar 4, 2019):

Hello all,

Same question here, I test by launching this command :
/usr/bin/firejail --profile=/etc/firejail/ssh.proile -c /usr/lib/openssh/sftp-server -l INFO

I have an can't connect to my SFTP client with this error:

subsystem request for sftp by user testsftp failed, subsystem not found

Same problem with --noprofile and same problem with this in /etc/ssh/sshd_config :

Subsystem /usr/bin/firejail --profile=/etc/firejail/ssh.profile /usr/lib/openssh/sftp-server -l INFO

What is the best practices to firejail openssh SFTP server, please ?

Thanks in advance for your help !

<!-- gh-comment-id:469344774 --> @Gimly86 commented on GitHub (Mar 4, 2019): Hello all, Same question here, I test by launching this command : `/usr/bin/firejail --profile=/etc/firejail/ssh.proile -c /usr/lib/openssh/sftp-server -l INFO` I have an can't connect to my SFTP client with this error: `subsystem request for sftp by user testsftp failed, subsystem not found` Same problem with --noprofile and same problem with this in /etc/ssh/sshd_config : `Subsystem /usr/bin/firejail --profile=/etc/firejail/ssh.profile /usr/lib/openssh/sftp-server -l INFO` What is the best practices to firejail openssh SFTP server, please ? Thanks in advance for your help !
Author
Owner

@fevangelou commented on GitHub (Mar 6, 2019):

@chiraag-nataraj Did so, but SFTP completely craps out. Even moved the command to a shell script in case the syntax was causing issues. SFTP breaks entirely.

There must be a better way to do this. I'm surprised SFTP is not covered in the docs, blog posts etc.

<!-- gh-comment-id:470176132 --> @fevangelou commented on GitHub (Mar 6, 2019): @chiraag-nataraj Did so, but SFTP completely craps out. Even moved the command to a shell script in case the syntax was causing issues. SFTP breaks entirely. There must be a better way to do this. I'm surprised SFTP is not covered in the docs, blog posts etc.
Author
Owner

@rusty-snake commented on GitHub (Sep 10, 2019):

IMHO the best is:

###Subsystem sftp /usr/lib/openssh/sftp-server
# Enable to built-in implementation of SFTP
Subsystem sftp internal-sftp

# This section must be placed at the very end of sshd_config
Match Group exchangefiles
  # Force the connection to use the built-in SFTP support
  ForceCommand internal-sftp
  # Chroot the connection into the home directory of the user being authenticated
  ChrootDirectory %h
…

https://wiki.ubuntuusers.de/SSH/

If you only want to restrict file access, or get I something wrong?

<!-- gh-comment-id:529952642 --> @rusty-snake commented on GitHub (Sep 10, 2019): IMHO the best is: ``` ###Subsystem sftp /usr/lib/openssh/sftp-server # Enable to built-in implementation of SFTP Subsystem sftp internal-sftp # This section must be placed at the very end of sshd_config Match Group exchangefiles # Force the connection to use the built-in SFTP support ForceCommand internal-sftp # Chroot the connection into the home directory of the user being authenticated ChrootDirectory %h … ``` https://wiki.ubuntuusers.de/SSH/ If you only want to restrict file access, or get I something wrong?
Author
Owner

@rusty-snake commented on GitHub (Oct 13, 2019):

I'm closing here due to inactivity, please fell free to reopen if you have more questions.

<!-- gh-comment-id:541426449 --> @rusty-snake commented on GitHub (Oct 13, 2019): I'm closing here due to inactivity, please fell free to reopen if you have more questions.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: github-starred/firejail#1600
No description provided.