This guide explains how to set up and manage SSH keys for Ansible automation.
Run these commands from the project root:
cd credentials
ssh-keygen -t rsa -b 2048 -f "$(pwd)/ansible_hub_key"
This will create:
ansible_hub_key
(private key)ansible_hub_key.pub
(public key)
ssh -i ./ansible_hub_key root@your-server-ip
-
Copy the public key to your target server:
ssh-copy-id -i ./ansible_hub_key.pub root@your-server-ip
-
Set proper permissions:
chmod 600 ansible_hub_key
-
Update your
.env
file with the correct path:SSH_PRIVATE_KEY_PATH=./credentials/ansible_hub_key
If you're using an AWS EC2 instance:
-
Place your
.pem
key file in the credentials directory:cp /path/to/your-aws-key.pem ./credentials/
-
Set proper permissions:
chmod 400 ./credentials/your-aws-key.pem
-
Update your
.env
file with the PEM key path:SSH_PRIVATE_KEY_PATH=./credentials/your-aws-key.pem
-
Test the connection:
ssh -i ./credentials/your-aws-key.pem ubuntu@your-ec2-ip