关于使用ssh免密码登录需要秘钥

发布时间:2023年12月26日

这是目标服务器
在这里插入图片描述
命令如下 密码自己输入 建议输入空,passphrase

jenkins@692e812b9a9e:~/.ssh$ ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/var/jenkins_home/.ssh/id_rsa): id_rsa
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in id_rsa
Your public key has been saved in id_rsa.pub
The key fingerprint is:
SHA256:YhVm3gM2ScWmPZhW6dxc4rajNh/Q6COf3c72DWQLj2M jenkins@692e812b9a9e
The key's randomart image is:
+---[RSA 3072]----+
|       .O+..     |
|       =.== . .  |
|        oXo+ o   |
|       .= =+=    |
|      o.S ooo.o  |
|     . . . .o* . |
|        . o.E.+  |
|         o+= =...|
|         .oooo+.o|
+----[SHA256]-----+
jenkins@692e812b9a9e:~/.ssh$ ls
id_rsa  id_rsa.pub
jenkins@692e812b9a9e:~/.ssh$ cat id_rsa.pub
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQDwbp8GfDoavKl3is3tvEQ9EGyeNXhQH/CgD9kcjBjdCHlCTh2uYBuaVHMgHDr2RjbEe55ClPEHQOc8hH4p/ArFEy2fp0ZNkkgDuyc3YnC61tkU/ptsOihJiaE3a3VUgcHH2JtEUc1I8fTqx2XoXtL2abN1R+JUHwcpVNYFF1xgFoQhxTFpknus9lVaEsqPnC9cONpzes0hp0XMWWhjBRhvPlmwrlIf0tPQWqEvCWsV7LCIne7Y/Exsk8rxBq6hS+QpPS0q2v7TJ6O+x9T8mSJDVXmfvLKmU5RqRAgt3EgPHE3CKKAKp8ble7+y4BYVYRCo7EasbLz+zhKwf2FYno1jYENXukBHLYrSxIUXYhe9tBU2jA7vZlq1NXF2NOlqk6sPtEBHyaqzYCbq77XvszJIMxTXKzaJB4doKYvkiXeRarS1+iRsfE1vHxd7IsNVbIrf0TO8IYM65YZqKi+8VrIaPuVeIol1MtmHBkbMfdms+WtkljfzTq9gbr7rpXf3hG8= jenkins@692e812b9a9e

在这里插入图片描述
这里有报错,权限不合适,需要修改权限
chmod 600 .ssh/id_rsa.pub
jenkins@692e812b9a9e:~$ chmod 600 .ssh/id_rsa.pub

这是其他服务器连接创建秘钥的服务器
在这里插入图片描述
[root@k8smaster .ssh]# vi authorized_keys
[root@k8smaster .ssh]# pwd
/root/.ssh
[root@k8smaster .ssh]# cat authorized_keys
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQDwbp8GfDoavKl3is3tvEQ9EGyeNXhQH/CgD9kcjBjdCHlCTh2uYBuaVHMgHDr2RjbEe55ClPEHQOc8hH4p/ArFEy2fp0ZNkkgDuyc3YnC61tkU/ptsOihJiaE3a3VUgcHH2JtEUc1I8fTqx2XoXtL2abN1R+JUHwcpVNYFF1xgFoQhxTFpknus9lVaEsqPnC9cONpzes0hp0XMWWhjBRhvPlmwrlIf0tPQWqEvCWsV7LCIne7Y/Exsk8rxBq6hS+QpPS0q2v7TJ6O+x9T8mSJDVXmfvLKmU5RqRAgt3EgPHE3CKKAKp8ble7+y4BYVYRCo7EasbLz+zhKwf2FYno1jYENXukBHLYrSxIUXYhe9tBU2jA7vZlq1NXF2NOlqk6sPtEBHyaqzYCbq77XvszJIMxTXKzaJB4doKYvkiXeRarS1+iRsfE1vHxd7IsNVbIrf0TO8IYM65YZqKi+8VrIaPuVeIol1MtmHBkbMfdms+WtkljfzTq9gbr7rpXf3hG8= jenkins@692e812b9a9e
将生成的秘钥复制到根目录下面

访问在原来的服务器访问放了秘钥的服务器
在这里插入图片描述

文章来源:https://blog.csdn.net/qiao2458/article/details/135225105
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。