Created
November 19, 2021 22:55
-
-
Save galvarado/ad667ab206874a21ed5cc26bd029b86e to your computer and use it in GitHub Desktop.
Generate and copy ssh key to hosts (in order to play with ansible)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
USER=someuser | |
PASSWORD=somepass | |
FILENAME="hosts.txt" | |
echo "Creating ssh key..." | |
ssh-keygen -t rsa -P '' -f ~/.ssh/id_rsa -y | |
echo "Set StrictHostKeyChecking to no (/etc/ssh/ssh_config)..." | |
sed -i '/StrictHostKeyChecking/c StrictHostKeyChecking no' /etc/ssh/ssh_config | |
echo "Install sshpass..." | |
rpm -q sshpass || yum -y install https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm && yum -y install sshpass | |
echo "Copy to all hosts..." | |
while IFS='' read -r LINE || [[ -n "$LINE" ]]; do | |
echo "Working on $LINE" | |
sshpass -p $PASSWORD ssh-copy-id -i ${USER}@${LINE} | |
done < "$FILENAME" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment