Ansible ssh-key密鑰認證配置


對於被管理服務器做免密碼登錄設置

1.在管理服務器生成ssh-key密鑰

#ssh-keygen  //生成秘鑰

root@hsz:/etc/ansible# 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 public key has been saved in /root/.ssh/id_rsa.pub.

The key fingerprint is:

c5:5a:29:c4:d6:8d:f7:2c:46:f8:a3:c1:d8:e9:5b:06 root@hsz

The key's randomart image is:

+--[ RSA 2048]----+

|       ... +     |

|       .o.+.+    |

|       ..+== o   |

|        .=E = o  |

|        S. = o   |

|          o o    |

|           +     |

|          .      |

|                 |

+-----------------+

 

#回車回車就行

 

2.將秘鑰拷貝到被管理服務器上

#ssh-copy-id  -i ~/.ssh/id_rsa.pub -p 22 root@192.168.0.50

 

#一般這樣的命令就行,即被管理服務器的ssh端口默認

#ssh-copy-id 192.168.0.50

# 那么接下來就可以進行遠程操作了(將被管理服務器ip加到清單的情況下)

比如ping:

[root@hsz ~]# ansible 192.168.0.50 -m ping 
192.168.0.50 | SUCCESS => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/bin/python"
}, 
"changed": false, 
"ping": "pong"
}


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM