#ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Created directory '/root/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:OMY2Xk1t4/BXpKTD093IzllXOyetZw5DIv4EPbVAPOE root@graylog
The key's randomart image is:
+---[RSA 2048]----+
| o+.o o|
| =oB B+|
| = E.OoO|
| . . + B X *+|
| B S o + O o|
| + + o . * |
| . . .|
| |
| |
+----[SHA256]-----+
命令脚本copy-key.sh
#!/bin/bash
IFSBAK=$IFS
IFS=$'\n'
for line in $(cat /root/iplist);do
myip=$(echo "$line" | awk '{print $1}')
mypd=$(echo "$line" | awk '{print $2}')
/usr/bin/sshpass -p "$mypd" ssh-copy-id -i /root/.ssh/id_rsa.pub $myip
done
IFS=$IFSBAK
iplist文件
192.168.1.1 123456789
192.168.1.2 mima
192.168.1.3 key