python批量建立ssh key(密鑰)認證

來源:互聯網
上載者:User

指令碼在github:https://github.com/linuxyan/linuxyan/tree/master/python/Batch_create_pub_key

下載下來指令碼之後,首先我們要在管理機上建立公開金鑰,運行如下命令,一路斷行符號。

ssh-keygen -t rsa
建立好公開金鑰之後,我們來看指令碼。
其中的Batch_key.py和host.list就是我們所需要的檔案。
host.list中是儲存了第一次建立key所需要的帳號和密碼。
格式如下:

ip:port:user:passwd
例如:

192.168.18.46:22:root:123456
192.168.18.13:22:root:123456
然後修改Batch_key.py中的

home_dir = '/home/yan'
修改為你的家目錄,比如
home_dir = '/root'
我們來跑下指令碼看看效果:

[root@localhost Batch_create_pub_key]# python Batch_key.py
create Host:192.168.18.13 .ssh dir......
upload id_rsa.pub to Host:192.168.18.13......
host:root@192.168.18.13 auth success!

create Host:192.168.18.52 .ssh dir......
upload id_rsa.pub to Host:192.168.18.52......
host:root@192.168.18.52 auth success!

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.