登錄服務器每次都要手動輸入用戶名密碼,很繁瑣.
先貼出expect 最終的腳本:
#!/bin/zsh username="******" password="******" host="192.168.0.0" port=10086 expect -c "
# 回顯 send_user connecting\ to\ $host...\r\n
spawn ssh -p $port $username@$host expect {
# 匹配 password *\ password* { send $password\r;exp_continue} }
# 停留在當前服務器 等待用戶交互 interact "
腳本很簡單 就不解釋了 將腳本拷貝到 /usr/local/bin目錄下
在iterm2 => Preferences => profiles 做如下設置
設置完成后關閉窗口,在iterm 的菜單欄 選擇 Profiles => 選擇 配置的Names 也就是 阿里雲服務器,就會使用對應的腳本 進行服務器的連接啦
expect 腳本參考: http://www.cnblogs.com/lixigang/articles/4849527.html