晓你所晓,得你所得

Mac 使用ssh密钥文件登陆Linux服务器

Mac 可以使用终端登 Linux 服务器,但默认支持的账号密码登录,并不支持密钥文件登陆 Linux。所以,本次将的是如何使用 ssh 密钥文件登陆 Linux 服务器。

首先,要有密钥文件。可以从阿里云或者百度云、腾讯云下载,如果没有 ssh密钥文件,请自行创建,创建密钥文件的教程还是蛮多的。

Mac 使用ssh密钥文件登陆Linux服务器

其次,把密钥文件放在放在根目录或者根目录下「.ssh」文件夹内,随意。

然后,打开终端,使用快捷键「cmd + shift + k」打开「新建远程连接」

再然后,在左侧「服务」点击「+」新建一个服务,如下:

服务名称:晓得伐 #可以随意写
Bonjour 名称:xiaodefa #也可以随意写
要执行的命令:ssh -i ~/.ssh/xiaodefa.pem #ssh -i + 文件路径
在命令中包含用户名:☑️   
右侧 - 添加 - 服务器:xx.xxx.xx.xxx #服务器公网 IP

接下来,点击刚才新建「服务」的名称,再点击新建「服务器 IP」,在「用户」填上用户名「root」,全部命令如下:

ssh -i ~/.ssh/xiaodefa.pem root@xx.xxx.xx.xxx 

Mac 使用ssh密钥文件登陆Linux服务器

最后,点击「连接」即可连接服务器。终端会出现以下代码,然后输入「yes」

The authenticity of host 'xx.xxx.xx.xxx (xx.xxx.xx.xxx)' can't be established.
ECDSA key fingerprint is SHA256:7vcJKtxxxxxxxxxxxxxxxY/PXxxxxxxxxDOgwUBzI.
Are you sure you want to continue connecting (yes/no/[fingerprint])? 

yes

这时,终端会出现相对熟悉的界面,如下:


Welcome to Alibaba Cloud Elastic Compute Service !

Activate the web console with: systemctl enable --now cockpit.socket

Last login: Mon Sep 21 01:08:06 2020 from xx.xxx.xx.xxx
[root@XXXXXXXX ~]# 

同时,用户根目录下会生成「.ssh」文件夹以及「known_hosts」文件。

gao@gaos-iMac-Pro ~ % tree /Users/gao/.ssh
/Users/gao/.ssh
├── known_hosts
└── xiaodefa.pem

以上内容就是 Mac 使用 ssh 密钥文件登陆 Linux 服务器,记得我刚用 Mac 的时候,根本就没有搜到使用密钥文件登陆 Linux 服务器的文章,都是千篇一律的抄袭!现在自媒体时代下,网络环境真差!