Skip to main content

User

User account management on target hosts.

Methods

MethodDescription
List(ctx, hostname)List all user accounts
Get(ctx, hostname, name)Get a user by name
Create(ctx, hostname, opts)Create a user account
Update(ctx, hostname, name, opts)Update a user account
Delete(ctx, hostname, name)Delete a user account
ChangePassword(ctx, hostname, name, password)Change a user's password
ListKeys(ctx, hostname, name)List SSH authorized keys
AddKey(ctx, hostname, name, opts)Add an SSH authorized key
RemoveKey(ctx, hostname, name, fingerprint)Remove an SSH key by fingerprint

Usage

import "github.com/retr0h/osapi/pkg/sdk/client"

c := client.New("http://localhost:8080", token)

// List all users
resp, err := c.User.List(ctx, "_any")
for _, r := range resp.Data.Results {
for _, u := range r.Users {
fmt.Printf("%s uid=%d\n", u.Name, u.UID)
}
}

// Get a specific user
resp, err := c.User.Get(ctx, "web-01", "deploy")

// Create a user
resp, err := c.User.Create(ctx, "web-01", client.UserCreateOpts{
Name: "deploy",
Shell: "/bin/bash",
Groups: []string{"sudo", "docker"},
})

// Update a user (lock account)
lock := true
resp, err := c.User.Update(ctx, "web-01", "deploy", client.UserUpdateOpts{
Lock: &lock,
})

// Change password
resp, err := c.User.ChangePassword(ctx, "web-01", "deploy", "newpass123")

// Delete a user
resp, err := c.User.Delete(ctx, "web-01", "deploy")

// List SSH keys for a user
keysResp, err := c.User.ListKeys(ctx, "web-01", "deploy")
for _, r := range keysResp.Data.Results {
for _, k := range r.Keys {
fmt.Printf("%s %s %s\n", k.Type, k.Fingerprint, k.Comment)
}
}

// Add an SSH key
addResp, err := c.User.AddKey(ctx, "web-01", "deploy", client.SSHKeyAddOpts{
Key: "ssh-ed25519 AAAA... user@laptop",
})

// Remove an SSH key by fingerprint
removeResp, err := c.User.RemoveKey(ctx, "web-01", "deploy", "SHA256:abc123...")

Example

See examples/sdk/client/user.go for a complete working example.

SSH Key Types

SSHKeyInfoResult

FieldTypeDescription
HostnamestringTarget hostname
StatusstringOperation status
Keys[]SSHKeyInfoList of authorized keys
ErrorstringError message (if any)

SSHKeyInfo

FieldTypeDescription
TypestringKey type (e.g., ssh-ed25519)
FingerprintstringSHA256 fingerprint
CommentstringKey comment

SSHKeyMutationResult

FieldTypeDescription
HostnamestringTarget hostname
StatusstringOperation status
ChangedboolWhether the operation changed state
ErrorstringError message (if any)

SSHKeyAddOpts

FieldTypeDescription
KeystringFull SSH public key line (e.g., ssh-ed25519 AAAA...)

Permissions

Requires user:read for List, Get, and ListKeys. Create, Update, Delete, ChangePassword, AddKey, and RemoveKey require user:write.