- Here is a video tutorial
Scripts and configuration files are available
here:
- Install sshpass
SLES | openSUSE Leap 15.4
1
|
sudo zypper install sshpass
|
Debian
1
|
sudo apt install sshpass
|
Red Hat
1
|
sudo dnf install sshpass
|
- Create a file
and place a password for the ansible user to connect to remote hosts.
- Make the script read only for this user
1
|
chmod 400 pass_file_ansible
|
- Create a list of servers with IP addresses or hostnames
- Create a script
And add the below content
1
2
3
4
5
6
|
#!/bin/bash
ssh-keygen -t ed25519 -C "ansible@rancher.local"
servers=$(cat servers)
for i in $servers; do
sshpass -f pass_file_ansible ssh-copy-id -i ~/.ssh/id_ed25519.pub ansible@$i
done
|
-
Make sure that PasswordAuthentication has set boolean value to yes in /etc/ssh/sshd_config file on remote servers.
-
Make the script executable
1
|
chmod +x ssh-copy-id.sh
|
- Execute the script