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
Asked
Active
Viewed 2.2k times
3 Answers
14
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
Slizzered
- 1,396
Rob Calistri
- 334
2
For ssh password prompt, try to use ansible/ansible-playbook -k/--ask-pass. It will call sshpass(FYI, maybe OSX don't ship with sshpass by default).
For host key checking, add
[defaults]
host_key_checking = False
in ~/.ansible.cfg or /etc/ansible/ansible.cfg.
Or export ANSIBLE_HOST_KEY_CHECKING=False just like this manual says.
For ssh keys deploy, use authorized_keys module in ansible playbook. It's easier for user to keep the scripts idempotency.
jasonz
- 228
0
If you're ok with inputting the password once, the following script will copy your ssh key to a large number of hosts (listed in hosts.txt) very fast without having to put your password on the command line:
# sudo yum install moreutils sshpass openssh-clients
echo 'Input Password:';
read -s SSHPASS;
export SSHPASS;
parallel -i -j 25 sshpass -e ssh-copy-id '-o ConnectTimeout=10 -o StrictHostKeyChecking=no {}' -- `cat hosts.txt`;
export SSHPASS=''
Adam C.
- 1