Skip to main content

User SSH key

The authorized SSH keys of a user. osapi dsl behavior get --name sshkey and osapi dsl behavior method get show the same. Its chain shows each call that its examples make.

Behavior​

Namesshkey
DescriptionThe authorized SSH keys of a user
Placementnode
Ofuser
Areasecurity
Internalno
APIyes
CLIyes
Nextno
Platformsdebian, linux, darwin
Sudonone
Runsnone
Writes/home/*/.ssh/authorized_keys
Keeps stateno
Usesuser
Used bynone

Methods (3)​

NAMEVERBHTTPROUTEPERMISSIONDESCRIPTION
listreadGET/api/node/{hostname}/user/{name}/sshkeyuser:readList the authorized SSH keys of a user
createwritePOST/api/node/{hostname}/user/{name}/sshkeyuser:writeAdd an authorized SSH key to a user
deletewriteDELETE/api/node/{hostname}/user/{name}/sshkeyuser:writeRemove an authorized SSH key of a user

Types (3)​

NAMEINPUTOUTPUT
listListInput { name* }[]Key { type, fingerprint, comment, options }
createCreateInput { name*, key* }Result { fingerprint, changed }
deleteDeleteInput { name*, fingerprint* }Result { fingerprint, changed }

Settings (0)​

None. Declare them with behavior.Config.

Telemetry​

Spanbehavior.sshkey.<method>
Child spansbehavior.user.<method>, exec chown, exec dscl, exec useradd, exec chpasswd, exec usermod, exec userdel, exec id, file.write, file.remove, file.chmod
Metricsosapi_behavior_calls_total, osapi_behavior_duration_seconds, osapi_behavior_changes_total
Attributesosapi.behavior.name, osapi.behavior.method, osapi.behavior.verb, osapi.behavior.outcome, osapi.behavior.changed
Recorded inputsname (list, create, delete), fingerprint (delete)

Method list​

Namelist
Verbread
DescriptionList the authorized SSH keys of a user
DetailReads ~/.ssh/authorized_keys of the user through gohai, with the type, the SHA256 fingerprint, the comment and the options of each key. A user with no file has no keys. A user that the host does not have is not found.
HTTPGET
Route/api/node/{hostname}/user/{name}/sshkey
Permissionuser:read
Commandosapi client node user sshkey list
Input typeListInput
Output type[]Key

Input (1)​

FIELDTYPEREQUIREDCONSTRAINTSDESCRIPTION
namestringyespattern ^[a-z_][a-z0-9_-]*$?$, max length 32The user, such as alice

Output (4)​

FIELDTYPEDESCRIPTION
typestringThe key type, such as ssh-ed25519
fingerprintstringThe SHA256 fingerprint of the key
commentstringThe comment after the key, such as alice@laptop
optionsstringThe options before the key, such as from="10.0.0.0/8"

Examples (3)​

EXAMPLEINPUTOUTPUT
A user with keysname=osapitest[comment=osapitest@example, fingerprint=SHA256:mnpIO1El26FsWnOeLzppADcNXgXRNHh9MPNPLPvSCwk, type=ssh-ed25519] [comment=other@example, fingerprint=SHA256:a5CeY6Lh3ZXkJOqGyuwb24kQeVjgag1gc9ujzv++nhE, options=from="10.0.0.0/8", type=ssh-ed25519]
A user with no keysname=osapitest
A host key that gohai cannot readname=osapitest[comment=osapitest@example, fingerprint=SHA256:mnpIO1El26FsWnOeLzppADcNXgXRNHh9MPNPLPvSCwk, type=ssh-ed25519]

Method create​

Namecreate
Verbwrite
DescriptionAdd an authorized SSH key to a user
DetailAdds the key line to the end of ~/.ssh/authorized_keys of the user, and makes the directory and the file if they are missing, with modes 700 and 600, owned by the user. A key that the file has already, by its fingerprint, does not change it. A line with no public key is refused. A user that the host does not have is not found. It runs on the Debian family only, and elsewhere reports skipped.
HTTPPOST
Route/api/node/{hostname}/user/{name}/sshkey
Permissionuser:write
Commandosapi client node user sshkey create
Input typeCreateInput
Output typeResult

Input (2)​

FIELDTYPEREQUIREDCONSTRAINTSDESCRIPTION
namestringyespattern ^[a-z_][a-z0-9_-]*$?$, max length 32The user, such as alice
keystringyespattern ^[^\r\n]*$The public key line, such as ssh-ed25519 AAAA... alice@laptop, with options before it if any

Output (2)​

FIELDTYPEDESCRIPTION
fingerprintstringThe SHA256 fingerprint of the key
changedbooleanWhether the host changed

Examples (4)​

EXAMPLEINPUTOUTPUT
Add a keyname=osapitest, key=ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIJl85dcLw7lIdX+IyXEXT00CTCezv/2E1jvolleleo6Z osapitest@examplefingerprint=SHA256:mnpIO1El26FsWnOeLzppADcNXgXRNHh9MPNPLPvSCwk, changed=true
Add a second keyname=osapitest, key=ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIGLPeEZQDbhOrSIx6gISjxXIcREV3rwL517pX6m9G5jc other@examplefingerprint=SHA256:a5CeY6Lh3ZXkJOqGyuwb24kQeVjgag1gc9ujzv++nhE, changed=true
A key after a last line with no line breakname=osapitest, key=ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIGLPeEZQDbhOrSIx6gISjxXIcREV3rwL517pX6m9G5jc other@examplefingerprint=SHA256:a5CeY6Lh3ZXkJOqGyuwb24kQeVjgag1gc9ujzv++nhE, changed=true
A key the user hasname=osapitest, key=ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIJl85dcLw7lIdX+IyXEXT00CTCezv/2E1jvolleleo6Z osapitest@examplefingerprint=SHA256:mnpIO1El26FsWnOeLzppADcNXgXRNHh9MPNPLPvSCwk, changed=false

Method delete​

Namedelete
Verbwrite
DescriptionRemove an authorized SSH key of a user
DetailRemoves each line of the key with the fingerprint from ~/.ssh/authorized_keys of the user, and keeps the other lines as they are. A key that the file does not have, a user with no file, or a user that the host does not have, changes nothing. It runs on the Debian family only, and elsewhere reports skipped.
HTTPDELETE
Route/api/node/{hostname}/user/{name}/sshkey
Permissionuser:write
Commandosapi client node user sshkey delete
Input typeDeleteInput
Output typeResult

Input (2)​

FIELDTYPEREQUIREDCONSTRAINTSDESCRIPTION
namestringyespattern ^[a-z_][a-z0-9_-]*$?$, max length 32The user, such as alice
fingerprintstringyespattern ^[^\r\n]*$The SHA256 fingerprint of the key, as list shows it

Output (2)​

FIELDTYPEDESCRIPTION
fingerprintstringThe SHA256 fingerprint of the key
changedbooleanWhether the host changed

Examples (3)​

EXAMPLEINPUTOUTPUT
Remove a keyname=osapitest, fingerprint=SHA256:mnpIO1El26FsWnOeLzppADcNXgXRNHh9MPNPLPvSCwkfingerprint=SHA256:mnpIO1El26FsWnOeLzppADcNXgXRNHh9MPNPLPvSCwk, changed=true
A key the user does not havename=osapitest, fingerprint=SHA256:a5CeY6Lh3ZXkJOqGyuwb24kQeVjgag1gc9ujzv++nhEfingerprint=SHA256:a5CeY6Lh3ZXkJOqGyuwb24kQeVjgag1gc9ujzv++nhE, changed=false
A user that the host does not havename=nobody, fingerprint=SHA256:mnpIO1El26FsWnOeLzppADcNXgXRNHh9MPNPLPvSCwkfingerprint=SHA256:mnpIO1El26FsWnOeLzppADcNXgXRNHh9MPNPLPvSCwk, changed=false