• Home
  • Blog

Archieven

  • mei 2025
  • april 2025
  • oktober 2024
  • september 2024
  • september 2023
  • maart 2022
  • maart 2021
  • september 2020
  • september 2019
  • februari 2019
  • september 2018
  • september 2016
  • september 2015
Davici
  • Home
  • Blog

SFTP Server with SSH, Chroot, and authorized_keys

Setting up a secure SFTP server using OpenSSH is a common need for IT admins. One key aspect of hardening your SFTP setup is using ChrootDirectory to restrict users to their own file spaces. However, this introduces an often-overlooked detail: where to place the authorized_keys file for SSH key authentication.

Why Use SFTP with Chroot?

SFTP (SSH File Transfer Protocol) offers encrypted file transfers over SSH. Using ChrootDirectory in your SSH config restricts users to a specific directory, preventing them from accessing the rest of the server’s file system — a critical security measure.

Example config in /etc/ssh/sshd_config:

Subsystem sftp internal-sftp

Match Group sftpusers
    ChrootDirectory /sftp/%u
    ForceCommand internal-sftp
    AllowTcpForwarding no
    X11Forwarding no

Ensure the chroot path (e.g., /sftp/username) is owned by root and not writable by the user.

The authorized_keys Catch

SSH needs access to the user’s ~/.ssh/authorized_keys file before the chroot takes effect. If .ssh is inside the chroot, SSH can’t read the key — and authentication fails.

Solution: Keep .ssh Outside the Chroot

To use SSH key auth with chroot:

  1. Set the user’s home directory outside the chroot (e.g., /home/username)
  2. Place .ssh/authorized_keys there
  3. Set ChrootDirectory to something like /sftp/username
  4. Ensure proper ownership and permissions

Example:

useradd -m -d /home/username -s /sbin/nologin -G sftpusers username
mkdir -p /sftp/username/uploads
chown root:root /sftp/username && chmod 755 /sftp/username
chown username:sftpusers /sftp/username/uploads

# SSH Key Setup
mkdir -p /home/username/.ssh
cp id_rsa.pub /home/username/.ssh/authorized_keys
chown -R username:username /home/username/.ssh
chmod 700 /home/username/.ssh
chmod 600 /home/username/.ssh/authorized_keys

Tags

.NET Azure C# CTO Database DevOps Docker EDI Git HA IT developement director Microservices PostgreSQL SFTP Softwareontwikkeling Visual Studio Windows

Recent Posts

  • Technical Debt: een strategische aanpak voor duurzame softwareontwikkeling

  • How to set timezone in a Docker Windows Container

  • How to install fonts in a Docker Windows Container

  • Why WebView2 Applications Face Issues in the Program Files Folder (And How to Fix Them)

  • ClickOnce signing from Azure DevOps via Azure Key Vault

Tags: SFTP

Contact

Breda, Noord-Brabant, Nederland
info@davici.nl
K.v.K. 20099979
Twitter
LinkedIn

OVERIGE

  • Algemene Voorwaarden
  • Privacybeleid
  • Cookiebeleid

Copyright © 2025 — Davici. Alle rechten voorbehouden.

Designed by WPZOOM

Beheer toestemming
Om de beste ervaringen te bieden, gebruiken wij technologieën zoals cookies om informatie over je apparaat op te slaan en/of te raadplegen. Door in te stemmen met deze technologieën kunnen wij gegevens zoals surfgedrag of unieke ID's op deze site verwerken. Als je geen toestemming geeft of uw toestemming intrekt, kan dit een nadelige invloed hebben op bepaalde functies en mogelijkheden.
Functioneel Altijd actief
De technische opslag of toegang is strikt noodzakelijk voor het legitieme doel het gebruik mogelijk te maken van een specifieke dienst waarom de abonnee of gebruiker uitdrukkelijk heeft gevraagd, of met als enig doel de uitvoering van de transmissie van een communicatie over een elektronisch communicatienetwerk.
Voorkeuren
De technische opslag of toegang is noodzakelijk voor het legitieme doel voorkeuren op te slaan die niet door de abonnee of gebruiker zijn aangevraagd.
Statistieken
De technische opslag of toegang die uitsluitend voor statistische doeleinden wordt gebruikt. De technische opslag of toegang die uitsluitend wordt gebruikt voor anonieme statistische doeleinden. Zonder dagvaarding, vrijwillige naleving door je Internet Service Provider, of aanvullende gegevens van een derde partij, kan informatie die alleen voor dit doel wordt opgeslagen of opgehaald gewoonlijk niet worden gebruikt om je te identificeren.
Marketing
De technische opslag of toegang is nodig om gebruikersprofielen op te stellen voor het verzenden van reclame, of om de gebruiker op een site of over verschillende sites te volgen voor soortgelijke marketingdoeleinden.
Beheer opties Beheer diensten Beheer {vendor_count} leveranciers Lees meer over deze doeleinden
Bekijk voorkeuren
{title} {title} {title}