update_script/ssh-copy-id.sh

16 lines
516 B
Bash
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

#!/bin/bash
# 新增服务器列表
servers=("101.42.178.28" "43.138.74.65" "101.43.235.69" "43.138.57.52" "43.143.136.9")
# 本地计算机的SSH公钥路径
local_public_key="$HOME/.ssh/id_rsa.pub"
# 远程主机的用户名和密码
remote_user="root"
remote_password="zEwwBkTivMKGuNpJ77mh"
for server in "${servers[@]}"; do
# 使用sshpass命令将密码传递给ssh-copy-id并将公钥追加到服务器
sshpass -p "$remote_password" yes|ssh-copy-id -i "$local_public_key" "$remote_user@$server"
done