Mac中實(shí)現(xiàn)iTerm2 SSH自動(dòng)登錄的方法

在 Mac 中用 Parallel Desktop 安裝了 Ubuntu Server 的虛擬機(jī),而 Mac 下的 iTerm2 本就是一款很不錯(cuò)的 Terminal 工具,但默認(rèn)情況下,需要手動(dòng)輸入 SSH 的登錄腳本,是一個(gè)比較低效的動(dòng)作。

實(shí)現(xiàn)自動(dòng)登錄是一個(gè)很自然的想法,而 iTerm2 也正好提供了自動(dòng)執(zhí)行腳本機(jī)制,如下簡(jiǎn)單的幾步即可實(shí)現(xiàn):

1. 編寫(xiě)自動(dòng)登錄的 bash 腳本
#!/usr/bin/expect -f
set user andy
set host 10.211.55.3
set password 12345678
set timeout 30
spawn ssh $user@$host
expect "*assword:*"
send "$password\r"
interact
expect eof
2. 務(wù)必將 bash 腳本文件的權(quán)限修改為可執(zhí)行
3. 設(shè)置 iTerm2 Profile

iTerm2 - Preferences - Profiles 打開(kāi)設(shè)置界面。點(diǎn)擊左下角的“+”創(chuàng)建一個(gè)新的 Profile,在右側(cè) Command 設(shè)置第一步腳本的路徑,在 Name 中設(shè)置名稱以及快捷鍵,如下圖所示

Profiles設(shè)置界面
3. 執(zhí)行 Profile

Profiles - Ubuntu-Server,執(zhí)行指定的 Profile 自動(dòng)執(zhí)行腳本,執(zhí)行結(jié)果如下

spawn ssh andy@10.211.55.3
andy@10.211.55.3's password:
Welcome to Ubuntu 18.04.1 LTS (GNU/Linux 4.15.0-38-generic x86_64)

 * Documentation:  https://help.ubuntu.com
 * Management:     https://landscape.canonical.com
 * Support:        https://ubuntu.com/advantage

  System information as of Thu Oct 25 13:12:16 UTC 2018

  System load:  0.08              Processes:             108
  Usage of /:   6.2% of 62.74GB   Users logged in:       1
  Memory usage: 16%               IP address for enp0s5: 10.211.55.5
  Swap usage:   0%


89 packages can be updated.
35 updates are security updates.


Last login: Thu Oct 25 13:11:43 2018 from 10.211.55.2
To run a command as administrator (user "root"), use "sudo <command>".
See "man sudo_root" for details.

andy@andy-ubuntu-server:~$
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容