sshpass自动登录

mac安装wget http://sourceforge.net/projects/sshpass/files/sshpass/1.05/sshpass-1.05.tar.gztar xvzf sshpass-1.05.tar.gz./configure --prefix=/usr/local/Cellar/sshpass/1.05makesudo make install

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

参考

  1. mac下使用sshpass实现ssh记住密码

关键字:linux, shell