ssh无密码非交互自动登陆及获取服务器运行时间及登陆有几个用户

#!/bin/bash
#Description
non_passwd_login ()
{
rm -rf /root/.ssh/id_rsa
yum -y install sshpass

ssh-keygen -t rsa -f /root/.ssh/id_rsa -N "" &> /dev/null

for ip in 246
do
sshpass -p123 ssh-copy-id -o StrictHostKeyChecking=no 192.168.8.$ip &> /dev/null
done
}


get_uptime ()
{
for ip in 246
do
run_time=`ssh 192.168.8.$ip uptime |awk '{print $3,$4}'`
echo "192.168.8.$ip uptime: $run_time"
done
}


main ()
{
non_passwd_login
get_uptime
}

main

 

 

posted @ 2023-07-18 09:39  往事已成昨天  阅读(19)  评论(0编辑  收藏  举报