Git服务器 生成 SSH 公钥

生成 SSH 公钥
许多 Git 服务器都使用 SSH 公钥进行认证。 为了向 Git 服务器提供 SSH 公钥,如果某系统用户尚未拥有密钥,必须事先为其生成一份。 这个过程在所有操作系统上都是相似的。 首先,你需要确认自己是否已经拥有密钥(默认情况下,用户的 SSH 密钥存储在其 ~/.ssh 目录下)。
快速确认自己是否已拥有密钥

$ cd ~/.ssh
$ ls

如果已经拥有密钥输入ls后将输出如下内容

id_rsa  id_rsa.pub  known_hosts

如果尚未拥有密钥则输出

known_hosts

运行 ssh-keygen 程序来创建密钥(在 Linux/Mac 系统中,ssh-keygen 随 SSH 软件包提供;在 Windows 上,该程序包含于 MSysGit 软件包中)

ssh-keygen    
Generating public/private rsa key pair.
Enter file in which to save the key (/mnt/localdata/localhome/your name/.ssh/id_rsa): 
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /mnt/localdata/localhome/your name/.ssh/id_rsa.
Your public key has been saved in /mnt/localdata/localhome/your name/.ssh/id_rsa.pub.
The key fingerprint is:
28:55:19:9b:b0:5e:6f:d2:8e:66:1d:7d:d9:0c:5d:ab your name@ubuntu
The key's randomart image is:
+--[ RSA 2048]----+
|  .              |
| . =         .   |
|. + o     . . .  |
| . . . . . . .   |
|.  .. o S = .    |
|. . oo . o E     |
| . ..+. .        |
|   o=.           |
|  o. .           |
+-----------------+

ssh-keygen 会确认密钥的存储位置(默认是 .ssh/id_rsa),然后它会要求你输入两次密钥口令。如果你不想在使用密钥时输入口令,接按Enter即可。
进行了上述操作后需要将各自的公钥发送给 Git 服务器管理员(假设服务器正在使用基于公钥的 SSH 验证设置)。 那么要做的就是复制各自的 .pub 文件内容,添加到Git服务器上。
查看id_rsa.pub内容:

cat ~/.ssh/id_rsa.pub
//复制以下部分
ssh-rsa 
BBBBBB3Nz...........mraGFq9fum0iEzN 
your name@ubuntu

然后将上面的SSH.Key添加到服务器User Setting —> SHH Keys中
在这里插入图片描述

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
为了向Git服务器提供SSH公钥,你需要生成一对SSH公钥和私钥。具体步骤如下: 1. 确认是否已经拥有密钥,可以使用以下命令查看密钥: ``` ssh-keygen -l -f ~/.ssh/id_rsa.pub ``` 2. 如果你还没有密钥,需要生成一份。在Git命令窗口中,输入以下命令配置用户信息: ``` git config --global user.name "你的用户名" git config --global user.email "你的邮箱地址" ``` 3. 继续在Git命令窗口中输入以下命令,生成SSH公钥和私钥: ``` ssh-keygen -t rsa -C "你的邮箱地址" ``` 4. 生成成功后,你可以在`C:\Users\你的用户名\.ssh`目录下查看生成SSH密钥。你可以使用以下命令查看公钥内容: ``` cat ~/.ssh/id_rsa.pub ``` 通过以上步骤,你就可以成功生成并获取到你的SSH公钥了。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *2* [服务器上的 Git - 生成 SSH 公钥](https://blog.csdn.net/jerwey/article/details/107870952)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] - *3* [git如何生成ssh密钥 git生成配置ssh密钥key详细步骤](https://blog.csdn.net/beautifull001/article/details/125630765)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

DerMing_You

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值