This sample demonstrates a least-privilege SSH design where the service account authenticates only with a restricted authorized key. It uses non-interactive command execution plus passwordless sudo to validate and rotate local Linux account passwords.
Platform Script: RestrictedAuthorizedKeyExample.json
A Linux host where the Safeguard service account uses a restricted SSH key and passwordless sudo for a tightly limited command set.
| Operation | Description |
|---|---|
CheckSystem |
Verifies the service account can resolve the target user through sudo /usr/bin/id. |
CheckPassword |
Reads the managed account's /etc/shadow entry with sudo and compares the supplied password to the stored hash. |
ChangePassword |
Runs sudo /usr/bin/passwd <user> non-interactively by sending the new password on stdin. |
DiscoverSshHostKey |
Retrieves the SSH host key for the asset. |
- A Linux host reachable over SSH
- A restricted service-account key configured in
UserKey - Passwordless
sudorights for the exact commands the sample runs, including/usr/bin/id,/usr/bin/cat /etc/shadow, and/usr/bin/passwd <user>
- Upload the script:
Import-SafeguardCustomPlatformScript -FilePath ./RestrictedAuthorizedKeyExample.json - Create a custom platform using this script
- Create an asset using the platform
- Configure service account and managed account(s)
- Test with
Test-SafeguardAssetAccountPassword -ExtendedLogging
The connection is opened with RequestTerminal: false, and every remote command is executed through a helper that always prefixes the command with sudo. CheckSystem resolves the target account, CheckPassword reads the shadow entry and compares it in-script, and ChangePassword drives passwd by supplying the new password twice on stdin. Unlike the broader batch-mode sample, this example intentionally fails if sudo requests a password, which keeps it aligned with a restricted-key, passwordless-sudo design.
UserKey- Required SSH private key for the restricted service account
- Assumes passwordless
sudo; the sample throws an error ifsudoprompts for a password - Uses fixed Linux command paths and manages only local accounts backed by
/etc/shadow - The restricted key policy must still allow the exact
sudocommands used by the sample