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为你之前设置的名字,这一连串的简单操作是不是非常简单便捷。

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