What server does

sudo vim /etc/ssh/sshd_config

打开如下选项:

PubkeyAuthentication yes

使用如下命令生成密钥:

ssh-keygen

cd .ssh

cat id_rsa.pub >> authorized_keys

重启sshd服务:

sudo systemctl restart ssh

What client does

复制.ssh目录下的id_rsa文件到~/.ssh目录下并重命名一个名字。

chmod 600 ./<your id_rsa name> 

编辑hostname

vim ~/.ssh/config

将以下内容添加进入:

Host <your server name>
HostName <your server IP>
TCPKeepAlive yes
ServerAliveInterval 15
User <your user name of server>
IdentityFile <your id_rsa file path>
Port <your server port>

尝试连接:

ssh <your server name>