How to Configure CentOS SFTP Only User

Published
Length
3 min read

Luis Felipe Dias

All posts

You set up a centos sftp only user by restricting OpenSSH to file transfers. You also lock that user account to one folder and block shell access. Teams often create standard Linux accounts when partners or apps need to move files. Those accounts grant interactive shell sessions by default. If permissions are too broad, a file transfer user can browse system folders. They can also run local scripts or read config files across the host. How a centos sftp only user works in OpenSSH OpenSSH han

User Provisioning (SCIM) + End-to-End Encryption: the complete guide

Architecture patterns, implementation strategies, and security best practices. Delivered to your inbox.

Free white paper. No spam. Unsubscribe anytime.

You set up a centos sftp only user by restricting OpenSSH to file transfers. You also lock that user account to one folder and block shell access.

Teams often create standard Linux accounts when partners or apps need to move files. Those accounts grant interactive shell sessions by default. If permissions are too broad, a file transfer user can browse system folders. They can also run local scripts or read config files across the host.

How a centos sftp only user works in OpenSSH

OpenSSH handles both interactive shells and secure file transfers over the same network port. To restrict an account, admins group file transfer users into a dedicated system group. Then they tell the SSH daemon to watch for logins from that group.

When a matched user logs in, OpenSSH forces the built-in SFTP subsystem to run. It ignores any shell command the client asks to execute. At the same time, OpenSSH changes the root directory for that session. This directory lock traps the user inside a chosen folder tree.

For this lock to work, the top folder must belong to the root account. No other user or group can have write rights on that top path. Inside that locked folder, admins create a writable subfolder for actual file uploads. The user can read and write files there without seeing the rest of the OS.

Using OpenSSH certificates for file transfer accounts

Managing static SSH keys or passwords for many transfer accounts takes constant work. OpenSSH offers a simpler certificate format than X.509 to solve this problem. Certificate login support arrived in OpenSSH 5.4 for both users and hosts.

An admin uses the key tool to sign a user public key with a CA key. The signed certificate holds the public key, identity info, principal names, and login options. Instead of copying public keys to every CentOS host, you trust the CA key.

User Provisioning (SCIM) + End-to-End Encryption: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

What native SFTP restrictions solve and what they miss

A native SFTP lock stops a file transfer user from opening a bash shell. It also keeps them out of system paths outside their assigned directory tree. This setup works well when external vendors upload batch files to a single drop box.

Still, host-level config files only decide who logs in and which folder they see. They do not track individual actions across many servers in one central place. Admins still have to edit local SSH settings and fix folder ownership on every node. If a root-owned parent folder gets wrong permissions, the login fails right away.

Static local accounts also leave credentials sitting on disk until someone removes them. Also, when engineers use SFTP or SSH to check production data, file locks cannot inspect content. They cannot mask sensitive fields like emails, phone numbers, card numbers, or national IDs. Controlling who logs in is only the first step. Teams also need clear audit logs and tight control over every active session.

Inspect one-shot SSH commands and file tasks

SSH certificates and host rules decide who is allowed on a machine. Setup alone does not check single commands or block sftp reads on sensitive paths. By design, hoop.dev runs an inline open-source SSH listener on the host where engineers and AI agents keep their normal ssh, sftp, and scp tools. On every production command or file operation, hoop.dev decides whether to pass, mask, block, or hold it for approval.

First, hoop.dev guardrails check one-shot commands and file paths before they run, and hoop.dev data masking masks matched values in file downloads. The audit trail logs the certificate principal, requested action, and verdict without storing session content. Interactive shells carry no guardrails and can be turned off when every action must be checked. Explore the code on GitHub.

Frequently asked questions

Why does my SFTP connection close right after login?

OpenSSH drops the session if the locked root folder has loose permissions. The top directory and every parent folder above it must belong to root. No other user can have write access to those parent directories.

Can an SFTP only user still run SSH port forwarding?

Yes, unless you turn forwarding off in your SSH daemon rules for that group. Forcing the internal SFTP subsystem only blocks shell commands. You must disable TCP and agent forwarding in the match block to stop tunneling.

How does an SFTP user upload files if root owns the locked folder?

Root must own the top locked folder, so the user cannot write directly inside it. You fix this by creating a child folder like uploads inside the locked path. Then you give the SFTP user ownership of that child folder.

Save the open-source gateway.

hoop is MIT-licensed infrastructure for controlling how AI agents reach production data. Star hoophq/hoop so you can inspect it, deploy it, or share it when your team starts governing agent access.