Authentication options
| Method | How | Use |
|---|---|---|
| Password | SSH password per host | Labs only; awkward at scale |
| Passwordless (keys) | SSH public key on managed nodes | Recommended |
Passwordless means: from the control node you run ssh ubuntu@managed-ip with no password and no -i pem — the control node’s private key authenticates.
Install Ansible on the control node
From your laptop, SSH into the control node, then:
sudo apt update
sudo apt install -y ansible
ansible --versionGenerate SSH keys on the control node
On the control node:
ssh-keygen -t ed25519 -C "ansible-control"
# press Enter for defaults (empty passphrase for labs)
ls ~/.ssh/
# id_ed25519 (private)
# id_ed25519.pub (public)Copy managed-node PEMs to the control node (bootstrap)
You still need the original EC2 .pem files once, to place the control node’s public key on each managed host.
From your laptop:
scp -i control-node.pem managed-node-1.pem ubuntu@<CONTROL_IP>:~/
scp -i control-node.pem managed-node-2.pem ubuntu@<CONTROL_IP>:~/On the control node:
chmod 400 ~/managed-node-1.pem ~/managed-node-2.pemInstall the control node public key on managed nodes
On the control node:
ssh-copy-id -i ~/.ssh/id_ed25519.pub -o IdentityFile=~/managed-node-1.pem ubuntu@<MANAGED_1_IP>
ssh-copy-id -i ~/.ssh/id_ed25519.pub -o IdentityFile=~/managed-node-2.pem ubuntu@<MANAGED_2_IP>If ssh-copy-id is unavailable, manually append ~/.ssh/id_ed25519.pub into each managed node’s ~/.ssh/authorized_keys, then:
chmod 700 ~/.ssh
chmod 600 ~/.ssh/authorized_keysTest passwordless SSH
From the control node (no -i, no password):
ssh ubuntu@<MANAGED_1_IP>
ssh ubuntu@<MANAGED_2_IP>First inventory + ping
On the control node:
# inventory.ini
[web]
prod-managed-node-1 ansible_host=<MANAGED_1_IP>
prod-managed-node-2 ansible_host=<MANAGED_2_IP>
[web:vars]
ansible_user=ubuntuansible all -i inventory.ini -m pingExpected: SUCCESS / "ping": "pong" for each host.
Production flow
Laptop → Control Node (Ansible)
↓ passwordless SSH
Managed Nodes
After passwordless SSH works, you can remove managed-node .pem files from the control node if you no longer need them. Keep the control node’s id_ed25519 private key safe.