# yum源[root@localhost ~]# cat /etc/yum.repos.d/epel.repo [epel]name=Extra Packages for Enterprise Linux 7 - $basearchbaseurl=http://mirrors.aliyun.com/epel/7/$basearchfailovermethod=priority
enabled=1gpgcheck=0gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7[epel-debuginfo]name=Extra Packages for Enterprise Linux 7 - $basearch - Debug
baseurl=http://mirrors.aliyun.com/epel/7/$basearch/debug
failovermethod=priority
enabled=0gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7gpgcheck=0[epel-source]name=Extra Packages for Enterprise Linux 7 - $basearch - Source
baseurl=http://mirrors.aliyun.com/epel/7/SRPMS
failovermethod=priority
enabled=0gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7gpgcheck=0
# 管理机安装ansible
yum -y install ansible
配置SSH密钥
[root@localhost ~]# ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.
Your publickey has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:G/0ENgVRPBWXkOwW27IF0Bhq4dwCQzzEUtTYhUw/RKo root@localhost.localdomain
The key's randomart image is:
+---[RSA 2048]----+
| BB*o*@Oo=.o|
| . ===Boo* o |
| . .B++..= |
| oo.o.= o |
| ES . o + |
| o o . |
| . . |
| |
| |
+----[SHA256]-----+
[root@Ansible1 ~]# ssh-copy-id -i /root/.ssh/id_rsa.pub root@10.22.86.72
/usr/bin/ssh-copy-id: INFO: Source ofkey(s) to be installed: "/root/.ssh/id_rsa.pub"
/usr/bin/ssh-copy-id: INFO: attempting to log inwith the newkey(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1key(s) remain to be installed -- if you are prompted now it isto install the new keys
root@10.22.86.72's password:
Number ofkey(s) added: 1
Now try logging into the machine, with: "ssh 'root@10.22.86.72'"and check to make sure that only the key(s) you wanted were added.
[root@Ansible1~]# ssh root@10.22.86.72Last login: Mon May 2908:54:222023from10.22.86.71
[root@Ansible2 ~]# exitlogout
Connection to 10.22.86.72 closed.
如果生成的密钥对不是默认的密钥名称,需要如下操作
# 假设生产的密钥对是id_rsa_test2
[root@Ansible1 ~]# ssh-keygen -f ~/.ssh/id_rsa_test2 -P'123456'
Generating public/private rsa key pair.
Your identification has been saved in /root/.ssh/id_rsa_test2.
Your publickey has been saved in /root/.ssh/id_rsa_test2.pub.
The key fingerprint is:
SHA256:ceWJTlaka6ejFgsmk+d7lpDmNRx0P7DYI3ZglBCv9Tw root@Ansible1
The key's randomart image is:
+---[RSA 2048]----+
| o+.. .+ |
| .= o* . |
| o+=*+o |
| o=O=.o |
| ..+S+E... |
| + B =. + |
| O + =o |
| o *. . |
| .=. |
+----[SHA256]-----+
[root@Ansible1~]# ssh-copy-id -i ~/.ssh/id_rsa_test2.pub root@10.22.86.72/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa_test2.pub"
/usr/bin/ssh-copy-id: INFO: attempting to log inwith the new key(s), tofilteroutany that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
Number of key(s) added: 1
Now try logging into the machine, with: "ssh 'root@10.22.86.72'"
andcheckto make sure that only the key(s) you wanted were added.
[root@Ansible1 ~]# ssh -i ~/.ssh/id_rsa_test2 root@10.22.86.72
Enter passphrase for key '/root/.ssh/id_rsa_test2':
Enter passphrase for key '/root/.ssh/id_rsa_test2':
Last login: Mon May 2909:16:392023 from 10.22.86.71
[root@Ansible1~]# ssh-copy-id -i ~/.ssh/id_rsa_test2.pub root@10.22.86.72/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa_test2.pub"
/usr/bin/ssh-copy-id: INFO: attempting to log inwith the new key(s), tofilteroutany that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
Number of key(s) added: 1
Now try logging into the machine, with: "ssh 'root@10.22.86.72'"
andcheckto make sure that only the key(s) you wanted were added.
[root@Ansible1~]# ssh-add/root/.ssh/id_rsa_test2
Enter passphrase for/root/.ssh/id_rsa_test2:
Identity added: /root/.ssh/id_rsa_test2 (/root/.ssh/id_rsa_test2)
[root@Ansible1~]# ssh-copy-id -i ~/.ssh/id_rsa_test3.pub root@10.22.86.73/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa_test3.pub"
/usr/bin/ssh-copy-id: INFO: attempting to log inwith the new key(s), tofilteroutany that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
Number of key(s) added: 1
Now try logging into the machine, with: "ssh 'root@10.22.86.73'"
andcheckto make sure that only the key(s) you wanted were added.
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· .NET Core 中如何实现缓存的预热?
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 如何调用 DeepSeek 的自然语言处理 API 接口并集成到在线客服系统