Skip to content

Instantly share code, notes, and snippets.

@galvarado
Created November 19, 2021 22:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save galvarado/ad667ab206874a21ed5cc26bd029b86e to your computer and use it in GitHub Desktop.
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)
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