Skip to content

Instantly share code, notes, and snippets.

@geunho
Created August 24, 2016 00:23
Show Gist options
  • Save geunho/819cb2f13cf68765e27adb44b40a5e98 to your computer and use it in GitHub Desktop.
Save geunho/819cb2f13cf68765e27adb44b40a5e98 to your computer and use it in GitHub Desktop.
원격 호스트에 ssh key를 한번에 복제
#!/bin/bash
#
# $1: key를 저장할 원격 호스트 사용자 아이디
# $2: 원격 호스트 사용자의 패스워드가 기록된 파일 경로
# $3: linebreak으로 구분된 원격 호스트 목록
# e.g. target_hosts
# myhost01
# myhost02
# myhost03
# ...
###########################################
user=$1
pwd=$2
target_hosts=$3
if [[ -z "$1" || -z "$2" || -z "$3" ]]; then
echo "Usage: copy-ssh-keys [user] [password-file] [target-hosts-file]"
exit 0
else
while read host; do
sshpass -f $pwd ssh-copy-id -o StrictHostKeyChecking=no $user@$host;
done <$target_hosts
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment