使用Terminal链接矩池云教程
因为Linux与MacOS都属于类类Unix系统,所以他们的Terminal链接方式都是大同小异的。我这里以Ubuntu20.04自带的Terminal为例,来介绍一下类Unix系统下的SSH链接。
口令登录
矩池云默认支持了随机的复制密码,可以直接复制ssh链接和密码,然后回车即可。
ssh -p 26035 root@hz.matpool.com
The authenticity of host '[hz.matpool.com]:26035' can't be established.
ECDSA key fingerprint is SHA256:kjNflO3R6SYR1/vgTYRT1VYqMziWFB4HrGi4Oq2y1go.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added '[hz.matpool.com]:26035' (ECDSA) to the list of known hosts.
root@hz.matpool.com's password:
(myconda) root@a705f4dd35b8:~#
类Unix系统的known_hosts文件默认在下面的路径内。
~/.ssh/known_hosts
密钥登录
一如既往的Ubuntu的密钥生成也是使用ssh-keygen命令来完成的。
cd ~/.ssh/
ssh-keygen
具体案例如下,
cd ~/.ssh/
matpool@matpool:~/.ssh$ ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/home/matpool/.ssh/id_rsa): matpool
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in matpool
Your public key has been saved in matpool.pub
The key fingerprint is:
SHA256:byZGgt+rncf/FntjrbGN9huFeelQOXfarQbouXVp5rQ matpool@matpool
The key's randomart image is:
+---[RSA 3072]----+
| |
| .|
| +o|
| . . .=*|
| . . S . ..+.=|
| . + o . .++.|
| . +.* . X=.|
| o *oo B+O+|
| ..+....+E==|
+----[SHA256]-----+
然后我们用cat命令来查看一下刚刚生成的公钥,然后将其上传到矩池云的我的公钥内。
cat ~/.ssh/matpool.pub
如果是按需租用矩池云,那么可以通过指定本地私钥地址来进行登录。
ssh -i ~/.ssh/matpool -p 22 user@host
案例如下,
ssh -i ~/.ssh/matpool -p 26035 root@hz.matpool.com
The authenticity of host '[hz.matpool.com]:26035' can't be established.
ECDSA key fingerprint is SHA256:kjNflO3R6SYR1/vgTYRT1VYqMziWFB4HrGi4Oq2y1go.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added '[hz.matpool.com]:26035' (ECDSA) to the list of known hosts.
Last login: Wed Jul 14 02:25:03 2021 from 172.17.0.1
(myconda) root@a705f4dd35b8:~#
第一次访问私钥的时候,Ubuntu会跳出一个提示框,输入系统的密码就可以了。
如果是包周包月包年等长期租用的用户可以使用密钥来进行免密登录。
matpool@matpool:~$ cd ~/.ssh/
matpool@matpool:~/.ssh$ ls
known_hosts matpool matpool.pub
matpool@matpool:~/.ssh$ vim conifg
案例如下,
# 写域名或者缩写,然后可以直接ssh matpool
Host matpool
# 矩池云分配的服务器域名
HostName hz.matpool.com
# 矩池云服务器的端口
Port 29722
# 矩池云用户名
User root
# 本地私钥地址
IdentityFile ~/.ssh/matpool
# 保持客户端与服务端会话在短时间内不会断开,单位是秒
ServerAliveInterval 360
可以直接复制如下,
Host matpool
HostName hz.matpool.com
Port 26035
User root
IdentityFile ~/.ssh/matpool
ServerAliveInterval 360
然后按一下键盘上的esc键,输入 :wq,回车即可保存成功。
然后回到Terminal内输入命令登录,这个时候不需要输入任何东西就会自动登录了。
ssh -p 26035 root@hz.matpool.com