sshpass自动登录

mac安装


wget http://sourceforge.net/projects/sshpass/files/sshpass/1.05/sshpass-1.05.tar.gz

tar xvzf sshpass-1.05.tar.gz

./configure --prefix=/usr/local/Cellar/sshpass/1.05

make

sudo make install

实例脚本

#!/bin/bash
    host=$1
    case "$host" in
        server1|ip_address1)
            exec sshpass -p password  ssh user@ip_address1 -p22
            ;;
        server2|ip_address2)
            exec sshpass -p password  ssh user@ip_address2 -p22
            ;;
        *)
        echo "no host found"
        ;;
    esac

参考

    原文作者:codecraft
    原文地址: https://segmentfault.com/a/1190000005686958
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞