Here sample way how to execute ssh-copy-id
with password by using sshpass
and answeringYES
for the first time connection
# install sshpass
sudo apt-get install sshpass -y # ubuntu
sudo yum install -y sshpass # centos
TEMP_PASS="MySecurePassword" # The password to pass over ssh
USER="root" # The user we going to use
REMOTE="IP_or_FQDN" # The IP of remote machine
echo "yes \n" | sshpass -p $TEMP_PASS ssh-copy-id -o StrictHostKeyChecking=no $USER@$REMOTE
You need to mark the file as executable: chmod +x auto-ssh.sh