ssh key公钥

本文详细介绍在Ubuntu系统中如何生成SSH密钥,包括检查本地是否有密钥、使用ssh-keygen命令生成新的密钥对、设置passphrase以及如何将生成的密钥添加到SSH代理中。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

在ubuntu上生成ssh key

首先使用

ls -al ~/.ssh

查看本地是否已经有key

如果没有会显示如下:

~$ ls -al ~/.ssh
ls: cannot access '/home/liuxueneng/.ssh': No such file or directory

使用ssh-keygen 生成新的key

提示 

Enter file in which to save the key (/home/liuxueneng/.ssh/id_rsa):

的时候直接回车按照默认名字就可以

提示

Enter passphrase (empty for no passphrase):
的时候最好输入passphrase并记住后面会用的到



liuxueneng@airfly-dev:~$ ssh-keygen  -t rsa -C "liuxueneng@iairfly.com"
Generating public/private rsa key pair.
Enter file in which to save the key (/home/liuxueneng/.ssh/id_rsa): 
Created directory '/home/liuxueneng/.ssh'.
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /home/liuxueneng/.ssh/id_rsa.
Your public key has been saved in /home/liuxueneng/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:aXmIOOJDa+H1Urcz6KAJBvg1Zu97S0OpDhAu1beseXQ liuxueneng@iairfly.com
The key's randomart image is:
+---[RSA 2048]----+
|                 |
|   .             |
|  o . .          |
|.o . + o =       |
|+ * O * E .      |
|.* X X B o       |
|..B * * *        |
|.o + O ..+       |
|  o   =o..       |
+----[SHA256]-----+

再次查看生成的key,可以看到id_rsa和 id_rsa.pub两个文件

ls -al ~/.ssh/
total 16
drwx------  2 liuxueneng liuxueneng 4096 Apr 24 13:53 .
drwx------ 15 liuxueneng liuxueneng 4096 Apr 24 13:55 ..
-rw-------  1 liuxueneng liuxueneng 1766 Apr 24 13:53 id_rsa
-rw-r--r--  1 liuxueneng liuxueneng  404 Apr 24 13:53 id_rsa.pub

接下来ssh-add 

如果出现提示“Could not open a connection to your authentication agent.”

则执行ssh-agent bash启动agent

再次ssh-add就可以了

 ssh-add ~/.ssh/id_rsa
Could not open a connection to your authentication agent.
liuxueneng@airfly-dev:~$ ssh-agent bash
liuxueneng@airfly-dev:~$ ssh-add ~/.ssh/id_rsa
Enter passphrase for /home/liuxueneng/.ssh/id_rsa: 
Identity added: /home/liuxueneng/.ssh/id_rsa (/home/liuxueneng/.ssh/id_rsa)

提示

Enter passphrase
的时候输入第一次设置的passphrase即可

转载于:https://www.cnblogs.com/tid-think/p/10762124.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值