使用公钥私钥不在讨论范围之内 这篇只记录一下使用expect
和sshpass
下载sshpass
links
安装sshpass
tar zxvf sshpass-1.05.tar.gz
cd sshpass-1.05
./configure && make
sudo make install
设置iTerm2
mkdir sshpass && touch sshpass/vagrant
echo 'vagrant' > vagrant # 写入密码
# iterm2->profiles->command 添加一下命令
/usr/local/bin/sshpass -f /Users/lePig/sshpass/vagrant ssh -p 1122 vagrant@127.0.0.1
第一次登陆验证秘钥问题,ssh的时候使用-o StrictHostKeyChecking=no
也可以在/etc/ssh/ssh_config 增加StrictHostKeyChecking=no
/usr/local/bin/sshpass -p 密码 ssh -o stricthostkeychecking=no -p 1122 vagrant@127.0.0.1
使用expect
方法
#!/usr/bin/expect -f
set host 主机地址
set user 用户名
set password 密码
set timeout -1
set port 22
spawn ssh -o StrictHostKeyChecking=no -p $port $user@$host
expect "*assword:*"
send "$password\r"
interact
expect eof