Linux – Copy the ssh key to remote machine via ssh-copy-id in a script without prompt

ansiblelinuxssh

My usecase is that i need to copy my ssh key for authorized access onto a remote machine. I need to be able to call a script that copies over my ssh key to the remote machine without needing my input. Currently it prompts for a password and also a yes to the RSA fingerprint.
I need it to be able to automatically add my hosts to each other via an IP range

Best Answer

I believe you can use sshpass.

  • Ubuntu/Debian: apt-get install sshpass
  • Fedora/CentOS: yum install sshpass

For example:

sshpass -p "PASSWORD" ssh-copy-id -o StrictHostKeyChecking=no USERNAME@IP

Related Question