M
M
Michael2019-06-03 16:58:11
linux
Michael, 2019-06-03 16:58:11

How to save ssh key on hosts?

Hello everyone,
I'm trying to implement ansible. Raised ansible on a separate machine and connected several servers.
To enter the server, I generate a key on the hosts, and then copy its ssh-copy-id to ansible-server.
But after the update, the ssh-key changes on the hosts and you have to generate the key again (go to hosts).
How can you keep the key permanent? Or after the update, upload the old one to hosts?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
P
pfg21, 2019-06-03
@ARMADIK

it is not clear how the ssh key on hosts can change?? it just doesn't change at all. some kind of brain updater??
system keys lie in /etc/ssh in the same place the main configs.
See /etc/ssh/ssh_config for user keys. usually in
# IdentityFile ~/.ssh/id_rsa
# IdentityFile ~/.ssh/id_dsa
# IdentityFile ~/.ssh/id_ecdsa
# IdentityFile ~/.ssh/id_ed25519
backup and restore.
but it is better to understand who is engaged in unauthorized activities.

I
Igor Deyashkin, 2019-06-03
@Lobotomist

To be honest, I don't understand what you're doing at all. I will describe how to do it in my opinion.
For authorization by key via ssh, the client must have a private key, and on the server to which it connects, the corresponding public key.
Ansible will by default run as your user (which you are running on the ansible machine). That is, you need to use the ssh-copy-id command to place the public key of this user on all the servers that you are going to manage. (You can also do this manually by editing the ~/.ssh/authorized_keys file on the server) .
You can also make it more convenient, in my opinion - so that when you connect to other servers from the ansible machine, your own key is used, and not the ansible user's key. To do this, on your machine, you need to enable AgentForwarding for the host with ansible:

Host myhost.com
  ForwardAgent yes

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question