Mac 讓 iTerm2 記住用戶名密碼 expect 腳本

剛剛用iTerm2的時候,老是要一遍遍的敲用戶名、密碼。 我在想, 能不能像Windows的軟件同樣,能夠直接讓軟件記住。而後只要點擊一下,就直接ssh到遠程服務器上面去了。
以後通過搜索,能夠用expect腳本實現。服務器

<code style="font-family: Monaco, Menlo, 'Courier New', monospace; margin: 2px; word-break: break-all; line-height: 18px; display: block; padding: 0px !important; border: none !important;">#!/usr/bin/expect

set timeout 30
spawn ssh -p [lindex $argv 0] [lindex $argv 1]@[lindex $argv 2]
expect {
        "(yes/no)?"
        {send "yes\n";exp_continue}
        "password:"
        {send "[lindex $argv 3]\n"}
}
interact</code>

這裏[lindex $argv 0], [lindex $argv 1], [lindex $argv 2], [lindex $argv 3] 分別表明着4個參數。ssh

將這個文件 item2login.sh 複製到 /usr/local/bin 就能夠了。 而後在iTerm2裏面配置。ui

如圖1:spa


而後看一條具體的實例code


<code style="font-family: Monaco, Menlo, 'Courier New', monospace; margin: 2px; word-break: break-all; line-height: 18px; display: block; padding: 0px !important; border: none !important;">item2login.sh 22 chenyuan 192.168.230.133 chenyuan</code>

腳本 端口號 用戶名 服務器地址 密碼 必定要一一對應blog


http://codingstyle.cn/topics/31ip

相關文章
相關標籤/搜索