Server Tools: SSH Users
Per-domain SSH users with Server Tools: create with ACL permissions, SSH keys and password, list, info and delete, which permissions are set and what limits the isolation has.
SSH Users
User management creates one system user per domain that accesses the files of that domain via SSH. Several developers share the user and each adds their own key.
The model is 1:1: one user belongs to exactly one domain. The tool recognizes every account with a home directory under /var/www/ and a UID of 1000 or higher as a domain user. The domain is derived from the directory name.
The user commands need neither Apache nor Nginx on the server. They require setfacl and getfacl from the package acl.
Create a user
server-tools user create --domain example.com --username exampledev
Prerequisites, checked in this order:
--domainis a valid domain name.--usernameis a POSIX name: lowercase letters, digits,_and-, starts with a letter or_, at most 32 characters. An existing account with a UID below 1000 is rejected.- The directory
/var/www/<domain>exists and is not a symlink. setfaclandgetfaclare installed andgetfacl /var/wwwworks, meaning the filesystem supports ACLs.- The domain does not have a user yet and the username is not taken.
- If there is no Apache configuration
<domain>.conffor the domain, the tool warns and asksContinue without vhost?. This also applies withST_WEBSERVER=nginx. ST_USER_DEFAULT_SHELLis an absolute, executable path. If it is not listed in/etc/shells, there is a warning.
Then the tool creates the user with useradd (home /var/www/<domain>, without creating a home directory, comment server-tools domain user for <domain>), creates .ssh and sets the permissions. If .ssh or the ACL setup fails, the user is deleted again and a newly created .ssh is removed.
The new user has no password and no key. Set both as described below.
Permissions
| Path | Owner | Additional permissions |
|---|---|---|
/var/www/<domain>/html |
The user (recursively, including the group of the same name) | ACL www-data: rwX, also as default for new files |
/var/www/<domain>/logs |
stays www-data |
ACL <user>: rX, also as default |
/var/www/<domain>/.ssh |
The user, mode 700 | authorized_keys with 600 |
html and logs must already exist under /var/www/<domain>, otherwise the ACL setup fails and the user is rolled back. A DocumentRoot elsewhere that you chose with vhost create --docroot is not covered by the tool.
The tool uses ACLs instead of chroot. It only changes permissions under
/var/www/<domain>. The user has a normal login shell and sees everything the system leaves readable for others. DocumentRoots created by the tool have mode 755, so other domains are readable for the user.
Add an SSH key
server-tools user add-key --username exampledev --key "ssh-ed25519 AAAAC3Nza... dev@laptop"
Allowed are ssh-rsa, ssh-ed25519, ecdsa-sha2-nistp256, ecdsa-sha2-nistp384, ecdsa-sha2-nistp521 and the FIDO variants with the prefix sk-. The key must be a single line of 40 to 8192 characters. An identical line that is already in authorized_keys is not added twice.
The tool checks that the account exists and has no UID below 1000. It does not check whether it is a domain user. The file authorized_keys is located in the home directory of the account.
Set a password
server-tools user set-password --username exampledev
server-tools user set-password --username exampledev --password 'a-long-password'
Without --password the tool generates a password with ST_PASSWORD_LENGTH characters. It is only shown if stdout is a terminal. In scripts a generated password is therefore not retrievable. Pass it there with --password. Passwords you set yourself need at least ST_PASSWORD_MIN_LENGTH characters and must not contain a colon.
List and info
server-tools user list
server-tools user info --username exampledev
list shows username, domain and shell of all domain users. info shows username, domain, UID, home, shell, the comment, the number of keys in authorized_keys and whether html belongs to the user and carries a www-data ACL.
Delete a user
server-tools user delete --username exampledev
The account must have a home under /var/www/. After the prompt this happens:
- The ACLs are removed and
htmlis given back towww-datarecursively. The user ACL onlogsis removed. - The directory
/var/www/<domain>/.sshis deleted along with all keys. - All processes of the user are terminated (SIGTERM, SIGKILL after one second, at most five more seconds of waiting).
userdelwithout-r.
Files in html are kept. Only after that can the VHost of the domain be deleted with vhost delete.