当前位置: 首页 > article >正文

ssh创建秘钥对

1. 使用ssh-keygen 生成秘钥对

[root@6zix89b87qmvuv ~]# ssh-keygen
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:nY1RwH7UrxNwLDtw8+GzbVpSxvCUSzROP34TILYaVcs root@6zix89b87qmvuv
The key’s randomart image is:
±–[RSA 2048]----+
| …=o=.+.|
| =.X @o+|
| o.= E.@o|
| .+=+ *.O|
| S.+… @.|
| = *|
| * |
| . |
| |
±—[SHA256]-----+

  1. 公钥私钥的默认位置在$HOME/.ssh

[root@6zix89b87qmvuv ~]# cd $HOME/.ssh
[root@6zix89b87qmvuv .ssh]# ll
total 20
-rw------- 1 root root 401 Jan 28 09:45 authorized_keys
-rw-r–r-- 1 root root 25 Mar 15 16:00 config
-rw------- 1 root root 1831 Mar 15 16:14 id_rsa
-rw-r–r-- 1 root root 401 Mar 15 16:14 id_rsa.pub
-rw-r–r-- 1 root root 517 Mar 15 16:06 known_hosts

  1. 将公钥发送至远程主机(172.31.0.12)

[root@6zix89b87qmvuv .ssh]# ssh-copy-id 172.31.0.12 (不必再公钥目录下)
/bin/ssh-copy-id: INFO: Source of key(s) to be installed: “/root/.ssh/id_rsa.pub”
/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/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@172.31.0.12’s password: 输入远程主机的密码

Number of key(s) added: 1

Now try logging into the machine, with: “ssh ‘172.31.0.12’”
and check to make sure that only the key(s) you wanted were added.

  1. 测试连接一下

[root@6zix89b87qmvuv .ssh]# ssh 172.31.0.12 默认使用root账号
Last login: Wed Mar 15 16:06:54 2023 from 172.31.0.4
[root@qn6t6bx1p0xo1o ~]# hostname -I 查看现在的ip
172.31.0.12 172.17.0.1 172.18.0.1


http://www.kler.cn/news/355.html

相关文章:

  • Golang每日一练(leetDay0005)
  • 算法题-相加为目标数之和(两数之和、三数之和、从数组中取n个数相加为m(不可重复取)、从数组中取任意个数相加为m(可重复取))
  • Windows逆向安全(一)之基础知识(二)
  • 「Vue面试题」动态给vue的data添加一个新的属性时会发生什么?怎样去解决的?
  • 【微信小程序】-- 网络数据请求(十九)
  • 嵌入式软件开发之Linux 用户权限管理
  • 一文带你吃透操作系统
  • java-正装照换底色小demo-技术分享
  • 用Python Flask为女朋友做一个简单的网站(附可运行的源码)
  • 【入门4 数组】P5728 【深基5.例5】旗鼓相当的对手——结构体
  • 2023年网络安全比赛--attack(新)数据包分析中职组(超详细)
  • 基于Qt WebEngine 的Web仪器面板GUI程控技术
  • 力扣-股票的资本损益
  • Linux磁盘和文件系统管理
  • 我一个普通程序员,光靠GitHub打赏就年入70万,
  • Matplotlib从入门到精通05-样式色彩秀芳华
  • 十大经典排序算法(上)
  • 30岁了,说几句大实话
  • 大数据核心技术是什么
  • Java代码是如何被CPU狂飙起来的?
  • 【2023-Pytorch-检测教程】手把手教你使用YOLOV5做电线绝缘子缺陷检测
  • 20230315整理
  • 宇宙最强-GPT-4 横空出世:最先进、更安全、更有用
  • 考研408 王道计算机考研 (初试/复试) 网课笔记总结
  • 史上最全最详细的Java架构师成长路径图,程序员必备
  • 01背包入门讲解
  • 程序员的逆向思维
  • AcWing算法基础课笔记 第一章 基础算法
  • 【数据结构】链表OJ(二)
  • 测试背锅侠?入职软件测试后大d佬给我丢了这个bug分类分析,至今受益匪浅......