相互免密,每台主机中执行如下脚本

#!/bin/bash
host_pass=1234
echo "---------ssh-keygen-----------"
expect -c "
        spawn ssh-keygen
        expect {
                "id_rsa" {send \r;exp_continue}
                "empty" {send \r;exp_continue}
                "again" {send \r}
};expect eof"
echo "---------install soft-----------"
yum install expect.aarch64 -y
echo "-----------send ssh key-------------"
for i in {1..8};
do
        echo "----------send for host$i-----------"
        expect -c "
        spawn ssh-copy-id 10.4.220.10$i
        expect {
                "yes/no" {send yes\r;exp_continue}
                "password" {send $host_pass\r}
        };expect eof"
done

批量修改主机名称 单台机器上执行

#/bin/bash
for i in {1..7};do
        ssh [email protected]$i hostnamectl set-hostname linux$i.skills.lan;
done