root@vpser:~# ssh-keygen -t rsa //先运行这个命令
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa): //直接回车
Created directory '/root/.ssh'.
Enter passphrase (empty for no passphrase): //输入密钥密码
Enter same passphrase again: //重复密钥密码
Your identification has been saved in /root/.ssh/id_rsa. //提示公钥和私钥已经存放在/root/.ssh/目录下
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
15:23:a1:41:90:10:05:29:4c:d6:c0:11:61:13:23:dd root@vpser.net
The key's randomart image is:
+--[ RSA 2048]----+
|=&@Bo+o o.o |
|=o=.E o . o |
| . . . |
| . |
| S |
| |
| |
| |
| |
+-----------------+
root@vpser:~#
将/root/.ssh/下面的id_rsa和id_rsd.pub妥善保存。
2、使用XShell生成密钥
Xshell是一款Windows下面功能强大的SSH客户端,能够按分类保存N多会话、支持Tab、支持多密钥管理等等,管理比较多的VPS/服务器使用XShell算是比较方便的,推荐使用。
下载XShell,安装,运行XShell,点击菜单:Tool ->User Key Generation Wizard,出现如下提示:
点击Save as file将密钥保存为id_rsa.pub。二、将密钥添加到远程Linux服务器
1、用winscp,将id_rsa.pub文件上传到/root/.ssh/下面(如果没有则创建此目录),并重命名为:authorized_keys(如果是在Linux服务器上生成的密钥直接执行:mv /root/.ssh/id_rsa.pub /root/.ssh/authorized_keys),再执行:chmod 600 /root/.ssh/authorized_keys 修改权限。