Skip to content

Instantly share code, notes, and snippets.

@mtsuszycki
Last active June 10, 2016 13:52
Show Gist options
  • Save mtsuszycki/b4b33e02a951baf7988784a2db99c720 to your computer and use it in GitHub Desktop.
Save mtsuszycki/b4b33e02a951baf7988784a2db99c720 to your computer and use it in GitHub Desktop.
execute remote command via ssh passwordlessly (no ssh keys) on many hosts
# execute remote command via ssh passwordlessly (no ssh keys) on many hosts
export SSHPASS=my_password # sshpass will use it
printf "host1\host2\n" | xargs -i sshpass -e ssh your_username@{} 'ls -la'
# or
cat hostlist.txt | xargs -i sshpass -e ssh your_username@{} 'ls -la'
# mass copy ssh public key onto many hosts
cat hostlist.txt | xargs sshpass -e ssh-copy-id -i ~/.ssh/id_rsa.pub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment