brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: ForceCommand internal-sftp with ChrootDirectory makes an SFTP-only SSH account

Network and access
~/tips/tip-sshd-sftp-only-chroot

ForceCommand internal-sftp

Give someone file upload access in one folder without a shell on the server.

Someone needs to drop files on your server, but should not get a shell or see the rest of the system. sshd can do that on its own, no FTP server needed.

At the end of /etc/ssh/sshd_config:

Match Group sftponly
    ChrootDirectory /srv/sftp/%u
    ForceCommand internal-sftp
    DisableForwarding yes

Members of the group sftponly get locked into their own folder. internal-sftp is the SFTP server built into sshd, so the chroot needs no copies of programs or libraries. DisableForwarding closes the tunnels, which ForceCommand alone does not block.

The part I’d watch most closely is ownership. The man page says every folder in the chroot path must be owned by root and not writable by group or others. So the user cannot write in the top folder itself; give them a subfolder:

sudo mkdir -p /srv/sftp/alice/upload
sudo chown root:root /srv/sftp/alice
sudo chmod 755 /srv/sftp/alice
sudo chown alice: /srv/sftp/alice/upload

If the ownership is wrong, the login fails with a vague disconnect on the client and a bad ownership or modes for chroot directory line in the server log. Check with sshd -t and restart, and test the account from another terminal before you log out.

Further reading: sshd_config man page

More Network and access tips scp -3 alice@server-a:/var/backups/db.sql.gz bob@server-b:/srv/restore/ tailscale exit-node suggest tailscale lock sign nodekey:1abddef1 tlpub:abcdef12 wg genpsk > peer1.psk Table = off All Network and access tips (163) All topics

Link