当前位置:网站首页>ssh-copy-id 批量免密脚本

ssh-copy-id 批量免密脚本

2022-06-21 05:40:00 瘋飆的蝸牛

#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 [email protected]
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

原网站

版权声明
本文为[瘋飆的蝸牛]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/172/202206210537447185.html