Shell script enables ssh-copy-id to automatically send public keys to remote hosts in batches
Demand
Batch realization of automatically sending public key to remote host
Environment
Firewalld: off
Selinux: off
Sshpass command shell calls the expect command sshpass command #! / bin/bash##****#Author: hechunping#QQ: × × # Date: 2019-11-07#FileName: ssh-sshpass.sh#URL: hexiaoshuai.blog.51cto.com#Description: The test script#Copyright (C): 2019 All rights reserved#*** * NET=172.20.200USER= (root hechunping) PASSWORD=123456ssh-keygen-t rsa-P''- f ~ / .ssh/id_rsa & > / dev/nullsed-I'/ StrictHostKeyChecking/c StrictHostKeyChecking no' / etc/ssh/ssh_configrpm-Q sshpass & > / dev/null | | yum-y install sshpass & > / dev/nullfor I in {1.. 254} Do {sshpass-p $PASSWORD ssh-copy-id-I ${USER [0]} @ ${NET}. ${I} & > / dev/null} & donewaitshell calls the expect command #! / bin/bash##* * # Author: hechunping#QQ: × × × # Date: 2019-11-07#FileName: ssh-expect.sh#URL: hexiaoshuai.blog.51cto.com#Description: The test script#Copyright (C): 2019 All rights reserved#** * * NET=172.20.200USER= (root hechunping) PASSWORD=123456ssh-keygen-t rsa-P''- f ~ / .ssh/id_rsa & > / dev/nullfor I in {1.. 254} Do {expect