Git使用SSH公钥

生成SSH公钥

你可以按如下命令来生成 ssh key:

ssh-keygen -t rsa -C "itldg"
其中的 itldg 为 ssh key 的名称
Generating public/private rsa key pair.
Enter file in which to save the key (C:\Users\Administrator/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in C:\Users\Administrator/.ssh/id_rsa.
Your publickey has been saved in C:\Users\Administrator/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:xxxxxxxxxxxxxxxxxxxxxxxx itldg
The key's randomart image is:
+---[RSA 3072]----+
| ..+ .o.E        |
|o  o*. .         |
|o..++   . .      |
| +.+ o   +       |
|o   B   S        |
|+.oo =  .        |
|o++BBo o         |
|. **Boo          |
| +BB.            |
+----[SHA256]-----+

按照提示完成三次回车,即可生成 ssh key。通过查看 ~/.ssh/id_rsa.pub 文件内容,获取到你的 public key

cat ~/.ssh/id_ed25519.pub
ssh-rsa xxxxxxxxxxxxxxxxxxx itldg

添加SSH公钥

在git平台中添加SSH公钥(以gitee为例)

验证使用

首次使用需要确认并添加主机到本机SSH可信列表。

ssh -T git@gitee.com
The authenticity of host 'gitee.com (212.64.63.215)' can't be established.
ECDSA key fingerprint is SHA256:xxxxxxxxxxxxxxx.
Are you sure you want tocontinue connecting (yes/no/[fingerprint])? 

输入yes,提示successfully 则证明添加成功。

Warning: Permanently added 'gitee.com,212.64.63.215' (ECDSA) to the list of known hosts.
Hi [36;01m老大哥[0m! You've [32msuccessfully[0m authenticated, but GITEE.COM does not provide shell access.

拉取测试

复制SSH的拉取地址(公开的仓库,可用于测试)

git clone git@gitee.com:itldg/vscode-ldggist.git
Cloning into 'vscode-ldggist'...
remote: Enumerating objects: 133, done.
remote: Counting objects: 100% (133/133), done.
remote: Compressing objects: 100% (130/130), done.
Receiving objects:  90% (120/133), 1.64 MiB | 3.21 MiB/seused 0
Receiving objects: 100% (133/133), 1.85 MiB | 3.49 MiB/s, done.
Resolving deltas: 100% (67/67), done.

至此配置完成,测试成功

Tortoisegit(小乌龟)配置

上述操作完成后,使用小乌龟拉取项目会提示错误

TortoiseGitPlink Fatal Error

No supported authentication methods available (server sent: publickey)

fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

将 SSH 客户端从 C:\Program Files\TortoiseGit\bin\TortoiseGitPlink.exe

修改为 Git 的目录 C:\Program Files\Git\usr\bin\ssh.exe

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值