1. 生成密钥(公钥和私钥)
2. 放置公钥(Public Key)到服务器~/.ssh/authorized_key文件中
3. 拷贝私钥(Private Key)自己妥善保存,用于认证
4. 配置使用ssh客户端使用密钥
使用命令生成公钥私钥
#1. 生成公钥和私钥
[root@home:~$] ssh-keygen
#2. 弹出提示
Generating public/private rsa key pair.
#3. 选择存放key的文件的位置
Enter file in which to save the key (/home/.ssh/id_rsa):
#4. 提示输入生成公钥私钥使用的密码,可以默认,直接回车就行
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
#5. 显示公钥私钥生成的位置,不带.pub的是私钥,带.pub是公钥
Your identification has been saved in /home/.ssh/id_rsa.
Your public key has been saved in /home/.ssh/id_rsa.pub.
#6. 剩余的输出的信息
The key fingerprint is:
SHA256:bEnqIod+P9hUbwjAvTLJX8WClWIgPDnxFqxm/ZSSPTg zhangfa@xjtuPC2
The key's randomart image is:
+---[RSA 2048]----+
| .o=oo o.o |
| =o+.= o o |
| *oB +.o |
| +.E B+o. |
| o O.=So |
| . .+.. o |
| o o+. . |
| . oo.o |
| .. ... |
+----[SHA256]-----+
在服务器上注册公钥
[root@home:~]$ cd .ssh/
# 将刚刚的公钥注册到authorized_keys中
[root@home .ssh]$ cat id_rsa_2048.pub >> authorized_keys
注意:如何权限不够,则可以进行权限修改
[root@home:~]$ chmod 600 authorized_keys
[root@home:~]$ chmod 700 ~/.ssh
下载公钥,使用私钥进行认证登录
点击确定连接即可
[root@home:~]$ cd .ssh/
# 将刚刚的公钥注册到authorized_keys中
[root@home .ssh]$ cat id_rsa.pub >> authorized_keys
上一篇
下一篇