#!/bin/bash
注:这个是远端已是密钥登录,才是有效的(key_id:为登录密钥)
#!/bin/bash
if [ $# != 1 ]; then
echo "错误: 请输入用户名"
exit
fi
useName=$1
cd /root/.ssh &&
ssh-keygen -t rsa -b 2048 -f $useName -C $useName -N '' &&
cat $useName".pub" >> authorized_keys && systemctl restart sshd &&
rsync -avrzLP -e "ssh -i key_id" $useName".pub" root@192.168.10.100:/root/.ssh/ &&
ssh -i /root/.ssh/key_id root@192.168.10.100 "cd /root/.ssh && cat ${useName}.pub >> authorized_keys && systemctl restart sshd"