Documentation
authorized_key
Add or remove SSH authorized keys for a user.
Attributes
check_mode:
support: full
Parameters
| Parameter | Required | Type | Values | Description |
|---|---|---|---|---|
| user | true | string | The username whose authorized_keys file should be modified. | |
| key | The SSH public key(s). Can be a single key string or a list of keys. | |||
| state | string | present absent |
Whether the key should be present or absent. [default: "present"] |
|
| path | string | Alternate path to the authorized_keys file. By default, uses ~/.ssh/authorized_keys. | ||
| exclusive | boolean | Whether to remove all other non-specified keys from the file. [default: false] |
||
| manage_dir | boolean | Whether to create the .ssh directory if it doesn’t exist. [default: true] |
||
| comment | string | A comment to attach to the key. By default, this is extracted from the key. | ||
| key_options | string | A string of ssh key options to be prepended to the key. |
Examples
- authorized_key:
user: deploy
key: ssh-rsa AAAA... user@host
state: present
- authorized_key:
user: deploy
key: '{{ lookup("file", "~/.ssh/id_rsa.pub") }}'
state: present
- authorized_key:
user: deploy
key:
- ssh-rsa AAAA... user1@host
- ssh-ed25519 AAAA... user2@host
state: present
- authorized_key:
user: deploy
key: ssh-rsa AAAA... old@host
state: absent
- authorized_key:
user: deploy
key: ssh-rsa AAAA... deploy@host
exclusive: true
key_options: 'no-port-forwarding,from="10.0.1.1"'