# 远程主机免密登录
以root用户登录到主控端机器,ssh-keygen生成密钥对,通过ssh-copy-id 远程主机,将公钥拷贝到远程主机
ssh-copy-id -i ~/.ssh/id_rsa.pub root@42.192.248.144
ssh-copy-id -i ~/.ssh/id_rsa.pub root@47.114.180.11
#####批量推送#######
批量推送公钥到远程机器
将以下文件命名为:push.ssh.ymal
- hosts: tencent
user: root
tasks:
- name: ssh-copy
authorized_key: user=root key="{{ lookup('file', '/root/.ssh/id_rsa.pub') }}"
tags:
- sshkey
# 执行推送命令
ansible-playbook push.ssh.ymal