1. 制作密钥
在服务器上制作密钥,用密码登录到你打算使用密钥登录的服务器账户,制作密钥:
[root@host ~]$ ssh-keygen <== 制作密钥
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa): <== 按 Enter
Created directory '/root/.ssh'.
Enter passphrase (empty for no passphrase): <== 密钥密码,或者按Enter设为空
Enter same passphrase again: <== 再次输入密钥密码
Your identification has been saved in /root/.ssh/id_rsa. <== 私钥
Your public key has been saved in /root/.ssh/id_rsa.pub. <== 公钥
The key fingerprint is:
0f:d3:e7:1a:1c:bd:5c:03:f1:19:f1:22:df:9b:cc:08 root@host
2. 在服务器上安装公钥
在服务器上安装公钥:
[root@host ~]$ cd .ssh
[root@host .ssh]$ cat id_rsa.pub >> authorized_keys
保证以下文件权限:
[root@host .ssh]$ chmod 600 authorized_keys
[root@host .ssh]$ chmod 700 ~/.ssh
3. 私钥下载至个人电脑上的远程客户端
把私钥 id_rsa
下载到本地,使用远程软件登录时,比如xshell,选择使用私钥登录。