Background
When using Ansible, to avoid the need to enter the SSH password each time a task is executed, we can cache the SSH key.
Caching SSH Keys with Ansible
- Start the ssh-agent background program
eval “$(ssh-agent -s)”
- Add the key to ssh-add, only input the password once
ssh-add ~/.ssh/xxx
- Verify if the key is successfully cached
ssh-add -l
