Back to blog

Giving someone access to three services on twelve servers, and nothing else

November 17, 2026 8 min read Kubexer Team
SSHsudoLeast PrivilegesystemdAccess Control

The request sounds small. A contractor, a new on-call engineer or a teammate from another squad needs to look after a few services on a handful of servers: check whether nginx is up, restart app-worker when it wedges, read its logs. That is it. They should not read the database credentials in /etc, install packages, or touch anything else on the box.

Doing that properly takes more than one command per host, and doing it on twelve hosts, then undoing it on a date, is where most teams quietly give up and hand over something broader.

What people do today

The common answers, in rough order of how often they are used:

  • Add them to a sudo or wheel group. Fast, and it means "root". The person can now do anything the service account can, and everything else too.
  • Share an existing login. One account, one key, passed around. Nobody can tell afterwards who did what, and you cannot remove one person without rotating for everybody.
  • Write a sudoers file per host by hand. This is the right idea, and the hardest to do safely. It is also tedious enough that it gets done once and never cleaned up.

The third option has sharp edges that are worth knowing even if you never use a tool for it.

Why a hand-written sudoers rule is easy to get wrong

The obvious rule is alice ALL=(root) NOPASSWD: /usr/bin/systemctl * nginx. It reads as "alice may run systemctl against nginx". It does not mean that. A wildcard in a sudoers command matches any arguments, so that line also allows systemctl edit nginx, which opens a root editor, and from there a root shell.

Logs have the same trap. A bare journalctl permission includes options such as --vacuum-size and --rotate, which change the journal rather than read it. And systemctl status pipes through a pager by default; a pager running as root is a well-known way to shell out. Each of these is fixable, but only if you know to fix it, and you have to be right on every host.

The safe shape is the boring one: list the exact command lines that are allowed, with no argument wildcards, and make sure paging is off for the ones that would otherwise page.

How Kubexer Terminal does it

An access profile in Kubexer Terminal is a description of one person's access that you can apply to many hosts at once. You create it inside a vault and fill in five things:

  1. The user. A name for the profile and the Linux username. The username is fixed once the profile is saved.
  2. A login key. Either generate a new ed25519 key, which is saved in the vault as an identity, or paste the person's own public key.
  3. Services. For each systemd service, tick which actions are allowed: status, start, stop, restart, reload and logs. You can load the list of real unit names from one of your hosts instead of typing them. Optionally, list config files they may edit.
  4. Hosts. Pick individual hosts or whole groups. Hosts added to a group later are picked up the next time you apply.
  5. When access ends. An optional expiry date, whether the account is locked or deleted at that point, and what a manual revoke does.

What lands on the host

Nothing is applied blind. Pressing Apply first runs a read-only check on every host as the user you connect with. It confirms the OS family (Debian, Ubuntu and RHEL-family distributions are supported), that systemd is version 239 or newer, that the commands it needs exist, and that the services you named are actually known to systemd on that host. You see which hosts are ready and can open the exact script that will run before you confirm.

Then, per host, it does the following as root:

  • Creates the Linux user with a home directory and writes the login key into its authorized_keys, writing it as that user so a symlink planted in their home cannot redirect the write.
  • Writes a sudoers file at /etc/sudoers.d/kubexer-<user> that contains only the exact command lines for the actions you ticked. For logs and status it includes the --no-pager forms, and the rule is marked NOEXEC as a second guard against a granted command spawning a shell. Both nginx.service and nginx are accepted, because people type both and sudo matches arguments literally.
  • Config files you listed are granted through sudoedit, which edits a temporary copy as the user and copies it back, so the editor never runs as root.
  • Writes the sudoers file to a staging name that sudo ignores, validates it with visudo, and only then moves it into place.

Each host is changed all-or-nothing. If a step fails partway, the script restores what it changed on that host. Progress is live per host, a host that needs a sudo password asks for it (once for all hosts, or skip that host), and Retry reruns only the failures.

The on-host manifest

Every applied host also gets a small JSON file at /etc/kubexer/access/<user>.json. It records which profile the user belongs to, the revision applied, the granted services, the expiry, and a status of active, revoked or expired.

This is what makes the whole thing safe to repeat. The next check reads that file and tells you, per host, whether the profile is absent, applied, out of date (you edited the profile since), expired or revoked. It is also why Kubexer refuses to touch an account it did not create: if the username already exists on a host without a matching manifest, the apply fails with a clear message instead of rewriting someone's real account. It will not manage the account it is itself connected with either.

Expiry that does not depend on your laptop

The part that most often fails with manual setups is the "and remove it in two weeks" half. Kubexer does not remember to do it for you. It installs a systemd timer on each host, named after the user, set to the expiry time in UTC. The timer is persistent, so if the host happens to be off at that moment, it runs at the next boot instead of never. As a backstop, the account's own shadow expiry date is also set, so logins stay refused even if the timer never fires.

When the timer, or you pressing Revoke, ends access, one helper on the host does the work in a deliberate order. The sudoers file is removed, the authorized_keys file is emptied, the shell is set to nologin, the account is expired, and only then are any live sessions terminated, since killing sessions first would leave a window to log straight back in. Depending on your setting, the account is then kept locked with its home folder, or deleted together with it. The manifest is marked revoked or expired and a line goes to syslog.

Because the helper lives on the host and the timer is owned by systemd, none of this needs Kubexer Terminal to be open when the time comes. Extending an expiry is just editing the profile and applying again.

Handing the key over: Share identity

A generated key is saved in the vault as an identity, and the person you are onboarding may not use Kubexer at all. For that there is Share identity: from the identity card, save a zip that contains the private key, the certificate if there is one, and a README.txt that explains how to install the key and connect on macOS, Linux or Windows with plain OpenSSH. The key file is written with owner-only permissions, as ssh expects.

Two honest cautions. Anyone who holds that zip can sign in as that user, so send it through a password manager share or an encrypted message, never plain email. And a key passphrase is not included in the zip; tell the person separately if there is one. Identities that sign through an SSH agent cannot be shared, because Kubexer holds no key to give. Sharing is free; Access Profiles are a Pro feature.

Limits you should know about

  • Granting config edits is close to granting root for that service. If someone can change a unit's configuration, they can change what it runs. Only grant it to people you would trust with that.
  • Deleting a profile in the app does not remove the user from any host. Revoke first, then delete.
  • Supported hosts are Linux with systemd 239 or newer, on Debian, Ubuntu or a RHEL-family distribution. Anything else is reported as unsupported during the check.
  • The account you connect with needs root or sudo. Applying a profile is itself a privileged act.
  • sshd settings are warned about, not changed. If a host limits logins with AllowUsers or AllowGroups, Kubexer tells you to allow the new user; it never edits sshd_config.
  • Least privilege is about commands, not data. Someone allowed to read a service's logs can read whatever that service writes there.

In short

Least privilege on Linux comes down to exact sudo rules, a per-person account, and an end date that is enforced on the host. Access Profiles generate those pieces from one description, check each host before touching it, and leave a manifest behind so the next check knows where things stand. Access Profiles are a Pro feature in Kubexer Terminal.