我是靠谱客的博主 等待人生,最近开发中收集的这篇文章主要介绍linux公钥配置,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

1、生成公私钥ssh-keygen -t rsa

[root@luoyuan home]# ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa): 
Enter passphrase (empty for no passphrase): 
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:
SHA256:krJf6ba/R57GFv5DQKWSXwfd5IymCAa/KbX0lt2/JxY root@luoyuan
The key's randomart image is:
+---[RSA 2048]----+
|      .      .ooo|
|       o   ... =o|
|        * o.. + +|
|       = * *.= . |
|    . + S = +..  |
|     o o o  o E. |
|    .   o  = + ..|
|     . o.   O + o|
|      ..ooo= o.+.|
+----[SHA256]-----+

输入以上命令,按三下Enter,出现如上图所示,公私钥存放位置为/root/.ssh目录下,id_rsa为私钥,id_rsa.pub为公钥,

2、复制当前服务器的公钥到目标服务器ssh-copy-id

[root@luoyuan .ssh]# ssh-copy-id root@192.168.220.1
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
root@slave01's password: 

Number of key(s) added: 1

Now try logging into the machine, with:   "ssh 'root@slave01'"
and check to make sure that only the key(s) you wanted were added.

root代码目标服务器的用户,192.168.220.1代表目标服务器ip,输入目标服务器密码,复制成功,目标服务器会有个authorized_keys文件

authorized_keys  id_rsa  id_rsa.pub  known_hosts

3、使用公钥登录 ssh 192.168.220.7

[root@localhost ~]# ssh 192.168.220.7
Last failed login: Mon Aug 12 23:15:41 CST 2019 on tty1
There was 1 failed login attempt since the last successful login.
Last login: Mon Aug 12 16:48:06 2019 from slave01

发现已经不需要使用密码

最后

以上就是等待人生为你收集整理的linux公钥配置的全部内容,希望文章能够帮你解决linux公钥配置所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(44)

评论列表共有 0 条评论

立即
投稿
返回
顶部