Script in Github:https://github.com/linuxyan/linuxyan/tree/master/python/batch_create_pub_key
After downloading the script, first we have to set up the public key on the management machine, run the following command, all the way to return.
SSH-KEYGEN-T RSA
After creating a good public key, let's look at the script.
The batch_key.py and host.list are the documents we need.
In Host.list, you save the account number and password required to create the key for the first time.
The format is as follows:
ip:port:user:passwd
For example:
192.168.18.46:22:root:123456
192.168.18.13:22:root:123456
Then modify the batch_key.py in the
Home_dir = '/home/yan '
Modify it for your home directory, such as
Home_dir = '/root '
Let's run the script to see the effect:
[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!