Solution for add keys mutual

Hi,

i want to enable ssh between two linux hosts.
i generate the ssh key on both hosts.
and then i need to add the keys on the other servers respectively

Does anyone has a ready solution for that?

greetings
Henrik

https://www.ssh.com/ssh/copy-id

Look at ssh-copy-id

thanx. but i need to address the other host. And i dont want to hard code the ip adress in this task

what do you mean? hard code what exactly?

the syntax for ssh-copy-id is: ssh-copy-id -i ~/.ssh/mykey user@host

And i want: from Host1 to Host2
and from host2 to host1

I don’t know how to specify the other host in a such a scenario

Do one host first then the other if you are doing this manually. If you are trying to use ansible to exactly do this steps then use the user module and authorized_key

I found a solution:

In my inventory files i put the remote IP and the remote ssh key.
In my task main.yml i use:

  • name: copy the ssh key
    authorized_key:
    user: root
    state: present
    key: “{{ remote_key }}”

that solve my problem.

Thanx for the help