Yeah i had this issue with Ansible - i had to convert the key to the openssh format in puttygen, but i could just export the private one so i thought its not possible - thank you i will try
I tested to convert the Key with -m RFC4716/PKCS8 but still invalid key specified i try to add the lines to convert in the playbook and try again but the samen.
Even with a new generated key.
If your screenshot was accurate, converting seems to work for me.
The key file contains:
---- BEGIN SSH2 PUBLIC KEY ----
Comment: "rsa-key-20240206"
AAAAB3NzaC1yc2EAAAADAQABAAABAQDKp5WjU+MEOBSeyqcDW48u5cOeInmiA5bm
Se99Nxo8QdBZ8AkyLreDQ37NXdacxziEEWknl+bcMwOGRDvQab8l8WGjn22vQsXM
DprFPkh4eY6aEwHjdbAmpy0z0jRWyWV6MClUBrBoD1wHn3YdKYevRGPRaajwz8Ec
wHbad5rGM9TH46V71ZGFebHyv3+KZe966+6m9y+xv0RRVGpu3lCCJTosqIwQDixu
1pwmJz4uyWhkBmviZ+ioW+d6L+VjzsbIxAsLp1a3qR2UbimUzgMMoMfDVir2B3nf
TEqj0Zn7ut1Mj+URL9OaLf0oIR7H5JZ33Q0E3LdWB4cngbwF+Fof
---- END SSH2 PUBLIC KEY ----
Playbook contains:
- hosts: all
gather_facts: no
vars:
key_path: /home/shertel/pub_key
tasks:
- name: Set authorized keys taken from local file
ansible.posix.authorized_key:
user: shertel
state: present
key: "{{ lookup('pipe', 'ssh-keygen -i -m RFC4716 -f ' + key_path) }}" # lookups run on localhost
validate_certs: false
If the error invalid key specified: ---- BEGIN SSH2 PUBLIC KEY ---- does not change at all after your conversion, it simply indicates that your playbook is not able to use the converted key file.
Therefore, it is important to know how you converted the file, where you placed the converted file, and how you are trying to read it from the playbook. Not stopping at simple explanations by some words, but presenting actual commands, the logs, the contents of actual YAML files, and your attempts as much as possible may help us a lot.
I have a last question because i wanted to see where the Key gets stored at the hosts, because i couldnt see it in the allowed_keys and te search for a part of the pub key is still running.
I believe your key is added into /<homedir for the user>/.ssh/authorized_keys on the target nodes, e.g. /home/charlietteeiiiaaste/.ssh/authorized_keys.
Note that you have the pub key in RFC4716 format, but you’ve added it after converting into OpenSSH format, so I bet the added keys in authorized_keys have different appearance than your original file. Therefore, if you search on a part of the original public key string, you will not find it.
I cant ssh with the key to the host.
What i can imagine is that the playbook doesnt contain a assigned user so it doesnt know where to put the key(?), but in the job the remote user is root…
In the successfull job i looked up i couldnt find any issues ans its still running.
The only home is from the user and the authorized_keys is empty.
I try to run the playbook with some more hosts to see if there is an global issue.