How to give clients SFTP or SSH access safely (chroot, keys, ACLs)
A freelancer needs to fix a theme, a client wants to upload files. Sharing one login is how servers get messy and insecure. Here's how to hand out SFTP and SSH access per person, with chroot jails, keys, ACLs and dedicated ports, and how to take it away again cleanly.
Sooner or later someone outside your team needs into a server. A freelancer has to fix a theme, a client wants to upload a batch of product photos, an external developer needs to run Composer. The quick answer is to send them the site's login, or worse, an account with sudo. It works, right up until you need to know who deleted that directory, or the freelancer's laptop gets stolen, or the project ends and you realise you can't revoke access without breaking everyone else's. Giving out SFTP and SSH access safely isn't hard, but it rests on a few rules that are easy to skip when you're in a hurry. Here they are.
Why one shared login is the real problem
Most access mistakes come down to sharing a single credential:
- No accountability. If three people use the same user, the logs can't tell you who changed what.
- No clean revocation. Removing one person means rotating the password or key for everyone, so in practice nobody gets removed.
- Blast radius. A shared account usually has more rights than any one person needs. One leaked credential exposes all of it.
The fix is a simple principle: one person, one account, the least access that does the job, and an expiry date in your head (or your calendar) for every account you create.
SFTP or SSH? Give the least you can
Start by asking what the person actually needs to do:
- Upload and edit files (designers, content people, most clients): SFTP only. No shell, no command execution, locked to the site's directory.
- Run tools such as Composer, WP-CLI, Artisan or Git (developers): a real shell, but still as an unprivileged user tied to that one site. Never sudo, never root.
SFTP-only covers far more cases than people assume. Every decent editor and file client (FileZilla, Cyberduck, WinSCP, VS Code extensions) speaks SFTP, and an SFTP-only account can't run anything on your server.
Chrooted SFTP with OpenSSH
OpenSSH has SFTP jails built in, no extra software required. A Match block in /etc/ssh/sshd_config restricts a user to SFTP and locks them into a directory:
Match User acme_anna
ChrootDirectory /var/www/acme
ForceCommand internal-sftp
AllowTcpForwarding no
X11Forwarding no
PasswordAuthentication no
ForceCommand internal-sftp means that whatever the client asks for, they get the SFTP subsystem and nothing else. ChrootDirectory makes /var/www/acme appear as / to them, so they can't even list the rest of the file system. Disabling forwarding stops the account being used as a tunnel into your internal network.
The one rule everybody trips over: the chroot directory itself must be owned by root and not writable by any other user or group, and the same goes for every directory above it. If it isn't, sshd refuses the login with a vague "bad ownership or modes" message in the auth log. The usual layout is a root-owned chroot with a writable subdirectory inside it, such as public_html, where the actual files live.
Before reloading sshd, always validate:
sshd -t && systemctl reload ssh
And keep your own SSH session open while you test from a second terminal. A typo in sshd_config should never be what locks you out of your own server.
One Linux user per person, with ACLs for shared files
If Anna and Ben both work on the same site, each gets their own Linux user, their own home directory and their own authorized_keys. The question is how both can write to the same public_html without sharing an identity.
The tempting shortcut is to add them to a common group such as www-data. Don't: on most servers that group is shared by every site, so membership quietly grants access to all of them. Use POSIX ACLs instead, which grant a specific user rights on a specific tree:
useradd --create-home --shell /usr/sbin/nologin acme_anna
setfacl -R -m u:acme_anna:rwX /var/www/acme/public_html
setfacl -R -d -m u:acme_anna:rwX /var/www/acme/public_html
setfacl -m u:acme_anna:--x /var/www/acme
The first setfacl grants read/write on existing files (capital X means execute only on directories). The second sets a default ACL, so files created later inherit the same rights. The third lets the user traverse the parent directory without being able to list it. getfacl shows you exactly who has access to what, which is also your audit trail when a project ends.
Keys over passwords, and how to restrict them
Key-based authentication beats passwords on every count: nothing guessable, nothing to phish, nothing reused from another site. Ask the person to generate a key on their own machine and send you only the public half:
ssh-keygen -t ed25519 -C "anna@agency.example"
The private key never leaves their laptop. You add the public key to their account's ~/.ssh/authorized_keys, and you can restrict it right there:
from="203.0.113.10",restrict ssh-ed25519 AAAAC3Nza... anna@agency.example
from= limits where the key may log in from, and restrict turns off port forwarding, agent forwarding and terminal allocation in one go. For a shell user who needs an interactive terminal, use restrict,pty.
If a client really can't cope with keys, passwords are acceptable for SFTP-only accounts as long as they're long (16+ characters, generated, unique) and you have Fail2Ban watching SSH. Enable password authentication only for that user in their Match block, and leave it off globally.
Dedicated ports: tidy, not magic
You can make sshd listen on extra ports and tie accounts to them:
Port 22
Port 2201
Match User acme_anna LocalPort 2201
...
A non-standard port won't stop a determined attacker, but it cuts the noise from bots hammering port 22, keeps client traffic separate from your admin access, and lets you allow or block one client's port in the firewall without touching anything else. Remember the firewall exists in two places on most cloud servers: the host firewall (UFW) and the provider's network firewall. Opening one and forgetting the other is the classic "the port is open but nothing connects" afternoon.
Revoking access properly
The project is over. Here's what actually removes access, and what only looks like it does:
passwd -ldoes not stop key logins. Locking the password leavesauthorized_keysworking. To disable an account temporarily, expire it instead (usermod --expiredate 1 acme_anna) or remove itsMatchgrant.- Existing sessions survive. Removing a key doesn't kill a connection that's already open. End it explicitly with
pkill -u acme_anna. - Clean up the ACLs.
setfacl -R -x u:acme_anna /var/www/acme/public_htmlremoves the user from the file tree before you delete them, so no orphaned numeric IDs remain. - Be careful with
userdel -r. It deletes the user's home directory. If that home happens to be a site's web root, you've just deleted the site. Know exactly what the home directory is before using it.
The traps to watch for
- Handing out sudo "just for this one task". Nobody ever takes it away again. Run the task yourself, or give a scoped shell user.
- Chroot ownership errors. Group-writable chroot directories are the number one reason SFTP jails "don't work".
- Shared groups as a permission shortcut. One group across every site means one compromised account can read every site.
- Editing sshd_config without
sshd -t. And without a second session open to fall back on. - Forgetting the cloud firewall when you open a new SSH port.
- No offboarding step. Accounts outlive projects by years unless removing them is part of closing the project.
How ShadowPanel handles it
Each of these steps is simple on its own; together, per person and per site, they make for a long checklist where one slip (a group-writable chroot, a forgotten firewall rule, a broken sshd_config) costs you an afternoon or your own access. ShadowPanel, our self-hosted hosting control panel, turns it into a form:
- Every site already has its own Linux user with SFTP chrooted to that site's directory, on every plan.
- Multiple SSH/SFTP accounts per site on the Pro plan (up to 3 per site) and the Agency plan (unlimited). Each account is a real Linux user with its own home and its own
authorized_keys, with write access to the site'spublic_htmlgranted through ACLs, never through the sharedwww-datagroup. - Per-account choices: access level SFTP (chrooted,
internal-sftp, no forwarding) or Shell, and authentication by key or password (minimum 12 characters). - A dedicated SSH port per site (2200 to 2299), shared by that site's accounts and opened in UFW automatically. Every sshd change is validated with
sshd -tand rolled back automatically if it fails, so a bad configuration can never lock you out. - Agency-only port lock: restrict an account to the site's custom port so it can't log in on the default port at all.
- Clean revocation. Disable an account to cut its SSH access while keeping it for later, or delete it to remove the Linux user and its ACLs; the site port is closed only once its last account is gone. Changes are recorded in the panel's audit log.
- Web terminal for admins. When you need a quick shell as a site's user yourself, open it in the browser (behind two-factor authentication) instead of creating yet another account.
That's especially handy for agencies working with outside freelancers across many client sites. (More on that setup in white-label hosting for agencies.) And if you're hardening the web side as well, see adding a ModSecurity WAF to Nginx.
The bottom line
Safe access comes down to a few habits: one account per person, SFTP-only unless a shell is truly needed, chroot jails with correct ownership, ACLs instead of shared groups, keys instead of passwords, and a real offboarding step that removes keys, sessions and ACLs. None of it requires special software, just discipline every single time. ShadowPanel builds that discipline into the panel, so adding or removing a freelancer takes a minute and never puts your server at risk.
curl -fsSL https://shadowpanel.de/install.sh | bash
Related articles
ModSecurity on Nginx with OWASP CRS: a practical WAF guide
A web application firewall catches SQL injection, path traversal and scanner noise before it ever reaches PHP. Here's ho...
How to clean a hacked website: find and remove malware
Spam redirects, a Google warning, a server suddenly sending mail: your site has been hacked. Here is how to contain it,...
Self-hosted uptime monitoring and a public status page, done right
Finding out your site is down from an angry client email is the worst way to learn it. Here is what to actually monitor,...