macOS登錄ssh的超炫酷方法

​ssh配置

ssh config配置

ssh-config是使用opensshssh config的功能,需要編輯~/.ssh/config這個文件。打開終端,然後輸入vi ~/.ssh/config

Host demo(這個隨你取名)HostName xx.x.x.x(你的服務器外網ip)User root(用戶名)Port 22(端口)

然後你就可以通過輸入ssh demo登錄你的服務器,當然這時候還需要輸入密碼。

免密方式登錄

如果你需要免密碼登錄的話,則需要配置祕鑰,這裏使用的是ssh-copy-id這個功能。

首先需要在本地生成祕鑰,打開終端,輸入如下命令:

ssh-keygen

然後將祕鑰複製到遠程的服務器

ssh-copy-id -i 用戶名@x.x.x.x

這時候需要輸入密碼,然後登錄遠程服務器,你就會在遠程服務器的~/.ssh/文件夾下發現一個authorized_keys文件,裏面就是我們剛剛複製的祕鑰了。

至此,你以後登錄遠程服務器就只需要在終端輸入ssh demo(你~/.ssh/config中設置的名字)就可以直接登錄遠程服務器了。

更加便捷的方式

使用Alfred

如果你不知道什麼是Alfred的話,可以跳過這一步,而且正版軟件要45歐元,當然網上的破解版本也很多。這個軟件可以通過快捷的命令完成設定的事。

打開alfred後,依次打開feature-Terminal,然後再Application中選擇Custom,然後在下面的框中輸入下面的命令。

on alfred_script(q) if application "iTerm2" is running or application "iTerm" is running then       run script "            on run {q}              tell application \":Applications:iTerm.app\"                    activate                    try                     select first window                     set onlywindow to true                  on error                        create window with default profile                      select first window                     set onlywindow to true                  end try                 tell the first window                       if onlywindow is false then                         create tab with default profile                     end if                      tell current session to write text q                    end tell                end tell            end run     " with parameters {q}   else        run script "            on run {q}              tell application \":Applications:iTerm.app\"                    activate                    try                     select first window                 on error                        create window with default profile                      select first window                 end try                 tell the first window                       tell current session to write text q                    end tell                end tell            end run     " with parameters {q}   end ifend alfred_script

參考:https://hacpai.com/article/1567998289912

在Alfred安裝中安裝ssh插件

插件下載地址:

https://github.com/deanishe/alfred-ssh

下載完成後,雙擊打開Secure-SHell-0.8.0.alfredworkflow並安裝就完成了。

將iTerm2設置爲ssh的默認打開程序

按照上圖,在iTem2的Preference中的Profiles中設置Schemes handled中選擇ssh。

享受便利

看下圖,只要輸入ssh name,其中name爲你之前設置的名字,這一連串的簡單操作是不是非常簡單便捷。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章