remote-backups.comremote-backups.com
Contact illustration
Sign In
Don't have an account ?Sign Up

SSH Sub-Users per Datastore: One Login per Client

You back up three clients into one datastore. All three use the same SSH login, so each client can read the files of the other two. Now you can give each client its own SSH sub-user. A sub-user has its own keys and sees only the folders that you grant to it.

Key Takeaways
  • Each datastore can now have SSH sub-users. A sub-user has its own SSH keys and can use only the folders that you grant to it.
  • The login of a sub-user is the main login, a dot and the sub-user name, for example customer<ID>.client-a. It connects to the same host as the main login.
  • Sub-users work with SFTP, rsync and Borg. They cannot run zfs. Proxmox Backup Server access does not use SSH, so sub-users do not change it.
  • You add a sub-user in the dashboard under Settings > SSH / SFTP. Resellers can also manage sub-users through the Reseller API.
  • When you delete a sub-user, its folders and files stay in the datastore. The main login keeps full access to all folders.

One datastore, one login per client

Until now, a datastore had one SSH login, customer<ID>. Every key that you added to it could reach every folder: sftp, borg and rsync, and everything below them. That is correct for one owner. It is a problem when you store data for several clients, for example as an MSP. You had to trust each client with the data of all the others, or book one datastore per client.

A sub-user solves this. You create it in the datastore, give it the public keys of one client, and select its folders. The client connects with its own login and sees only those folders. The other folders are not visible to it.

The login is the main login, a dot and the sub-user name:

bash
sftp -i /path/to/client-key customer<ID>.client-a@<host>
Connect as a sub-user with SFTP

The client keeps its private key. You add only its public key.

Add a sub-user

Create an SSH sub-user
1
Open the SSH settings

In the dashboard, open your datastore, go to Settings and select SSH / SFTP. Below the main SSH keys, click Add user.

2
Enter a name

Use lowercase letters, digits and -, at most 32 characters, for example client-a. The first character must be a letter or a digit. The form shows the login and an sftp command for it.

3
Paste the client's public keys

One key per line, in OpenSSH format (for example ssh-ed25519 ...). A sub-user can have up to 50 keys.

4
Select the folders

Expand sftp, borg or rsync and tick the folders the sub-user may use. A ticked folder includes everything below it. To make a new folder, click the folder icon next to its parent.

5
Save

Add an optional comment, then click Save. A folder that does not exist yet is created now. The table shows the login to give to your client.

To change the keys or the folders of a sub-user, click the edit icon. The change applies at the next login, because the server reads the folders of the sub-user from the service each time the sub-user logs in.

What a sub-user can do

A sub-user can read and write in its granted folders. It cannot see the other folders. The folders above its own are read-only, so it cannot put files next to them.

Main loginSub-user
Logincustomer<ID>customer<ID>.<name>
FoldersAllOnly the granted folders
SFTP, rsync, BorgYesYes, in its folders
ls, du, rm, mkdir and other commandsYesYes, in its folders
zfsYesNo

Each tool sees the folders in its usual place. In an SFTP session, the granted sftp folders show under /data, and the granted borg and rsync folders show under /borg and /rsync. FileZilla, WinSCP and other graphical clients work the same way: enter the full login as the user name. If you use SFTP from Nextcloud, the setup in Connect Nextcloud to Remote SFTP Storage works with a sub-user login too.

For rsync, paths start inside your rsync folder. A sub-user with the folder rsync/acme/daily writes to acme/daily/:

bash
rsync -avz -e "ssh -i /path/to/client-key" \
    /srv/backup/ customer<ID>.client-a@<host>:acme/daily/
rsync as a sub-user

A write to a folder that is not granted fails with "Read-only file system".

For Borg, put the repository inside a granted folder. For a sub-user with the folder borg/acme:

bash
export BORG_RSH="ssh -i /path/to/client-key"
borg init --encryption=repokey customer<ID>.client-a@<host>:./borg/acme/repo
borg create customer<ID>.client-a@<host>:./borg/acme/repo::{now} /path/to/files
Borg repository for a sub-user
Proxmox VE backups do not use SSH

Sub-users are SSH logins. Backups from Proxmox VE to the Proxmox Backup Server datastore use the datastore credentials, not SSH. To split that access, use credentials and ACLs. A sub-user does not change them.

How the isolation works

The service does not only hide the other folders. It builds a separate view of the datastore for each session:

  • For each login, the server reads the granted folders of the sub-user from the service. A key line for a deleted sub-user cannot log in, even if it is still on the host.
  • The session runs in a sandbox. The sandbox has an empty, read-only datastore mount that holds only the granted folders. For commands other than SFTP, the sandbox also hides the processes of the host.
  • A granted folder that contains a symbolic link stops the login. A link cannot point the session at the folder of another client.
  • Folder names cannot start with a dot or a dash, so a grant like .. is not possible.
The main login still sees everything

The main login keeps full access to all folders, including the folders of your sub-users. Do not give the main login keys to a client. Give each client a sub-user.

Remove a sub-user

Click the delete icon. The service removes the key lines of the sub-user from the host, and the next login of that sub-user fails. Its folders and files stay in the datastore. The main login can still use them or delete them.

Manage sub-users through the Reseller API

Resellers can do the same steps through the Reseller API:

plaintext
GET    /reseller/datastore/{id}/ssh-users
POST   /reseller/datastore/{id}/ssh-users
PATCH  /reseller/datastore/{id}/ssh-users/{name}
DELETE /reseller/datastore/{id}/ssh-users/{name}
GET    /reseller/datastore/{id}/folders
POST   /reseller/datastore/{id}/folders
Reseller API endpoints for sub-users

A folder in a request starts with sftp, borg or rsync, for example sftp/acme or rsync/acme/daily. A sub-user can have up to 100 folders.

Wrapping Up

SSH sub-users give each client its own login into a shared datastore, with its own keys and only its own folders. They work with SFTP, rsync and Borg. Add them in the dashboard under Settings > SSH / SFTP, or through the Reseller API. For the commands of the main login, see the SFTP, rsync, Borg and ZFS docs.

Set up SSH sub-users

The docs show the steps, the folder rules and the commands for SFTP, rsync and Borg.

Read the SSH users docs

The main login of the datastore, a dot and the sub-user name, for example customer<ID>.client-a. It connects to the same host as the main login.

No. A sub-user sees only its granted folders. The folders above them are read-only, and all other folders are not in its view.

No. A sub-user works with SFTP, rsync, Borg and the file commands such as ls, du, rm and mkdir. Backups from Proxmox VE use the datastore credentials, not SSH.

The folders and files stay in the datastore. The next login of the sub-user fails, and the main login can still use or delete the data.

At the next login of the sub-user. The server reads the granted folders from the service on each login.
Bennet Gallein
Bennet Gallein

remote-backups.com operator

Infrastructure enthusiast and founder of remote-backups.com. I build and operate reliable backup infrastructure powered by Proxmox Backup Server, so you can focus on what matters most: your data staying safe.