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