wsl使用git

前言:文章类型 > 笔记

安装git

sudo apt-get install git

查看版本(只用前面那句就行)

git --version; git credential-manager --version

用户配置

git config --global user.name "Your Name"
git config --global user.email "youremail@domain.com"

生成密钥

ssh-keygen -t rsa -C "youremail@domain.com"

查看并复制公钥

cat ~/.ssh/id_rsa.pub

bash 复制代码
# 你会看到类似这样的内容:
# ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQD...(很长一串)... youremail@domain.com

👌以下内容可忽略
👌SSH密钥指纹(Fingerprint)
👌以上内容为实践,以下内容由ai生成,可忽略。
👌介绍:

SSH密钥指纹(Fingerprint)

指纹是公钥的哈希值,主要用于验证公钥的真实性和唯一性,而不是用于身份认证。以下是指纹的主要用途:

验证公钥的真实性:当你第一次连接到远程服务器(如GitHub)时,SSH客户端会显示该服务器的公钥指纹,你可以通过对比已知的正确的指纹来确认你连接的是正确的服务器,而不是恶意的中间人。

唯一标识公钥:指纹是公钥的简短表示,方便人类比较和识别。公钥本身很长,而指纹较短,易于处理。

安全验证:在团队协作或自动化脚本中,可以通过比较指纹来确保使用的公钥是正确的。

在SSH连接过程中的作用:当你第一次通过SSH连接到新服务器时,会看到类似这样的提示:

text The authenticity of host 'github.com (140.82.121.3)' can't be

established. ECDSA key fingerprint is

SHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8. Are you sure you

want to continue connecting (yes/no)?

你可以通过对比GitHub官方公布的指纹(可以在GitHub的文档中找到)来确认你连接的是真正的GitHub服务器,而不是冒名顶替者。

在GitHub中,你也可以看到你添加的公钥的指纹,以便于管理。

所以,指纹是一个用来验证公钥的便捷工具,但并不是用于身份认证的凭证。身份认证时需要使用私钥,而远程服务器使用公钥来验证你的私钥。
SSH密钥指纹(Fingerprint)的主要用途是验证和识别密钥,而不是用于身份认证。以下是它的具体作用:

1. 验证密钥真实性(防止中间人攻击) 当你第一次连接新服务器时,SSH会显示服务器的公钥指纹: ```The authenticity of host 'github.com (140.82.121.3)' can't be established.

ECDSA key fingerprint is

SHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8. Are you sure you

want to continue connecting (yes/no)? ```你可以:

  • 对比GitHub官方公布的指纹(在GitHub文档中)
  • 确认你连接的是真正的GitHub,而不是假冒的服务器
2. 快速识别和区分密钥
  • 指纹是公钥的哈希值,短小易读
  • 便于人工核对,避免比较长长的公钥字符串
3. 在GitHub等平台上的用途
  • GitHub会显示你已添加密钥的指纹
  • 方便你确认添加了正确的密钥
  • 删除密钥时可以通过指纹识别
4. 实际使用场景示例
检查本机已添加密钥的指纹bash ssh-keygen -lf ~/.ssh/id_rsa.pub 输出: ```3072 SHA256:L8bheKiPGxAix5CX9OYQN/2qA33xv/GNugf4yw2JsXQ

youremail@domain.com (RSA) ```

查看GitHub服务器指纹bash ssh-keyscan github.com | ssh-keygen -lf - 输出(应与官方公布的一致): ```256 SHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8 (ECDSA) 256

SHA256:p2QAMXNIC1TJYWeIOttrVc98/R1BUFWu3/LiyKgUfQM (ED25519) 3072

SHA256:uNiVztksCsDhcc0u9e8BujQXVUpKZIDTMczCvj3tD2s (RSA) ```

验证连接到的服务器bash ssh -T git@github.com 首次连接会显示指纹让你确认。
5. 重要区别总结 | 项目 | 公钥 (Public Key) | 指纹 (Fingerprint) | |------|-------------------|---------------------| | 用途 |

身份认证(添加到GitHub) | 验证和识别 | | 格式 | 长字符串(ssh-rsa AAAAB3N...) |

短哈希值(SHA256:xxxx) | | 长度 | 几百个字符 | 几十个字符 | | 可逆性 | 原始数据 |

哈希值,不可逆 | | 使用场景 | 添加到服务端进行认证 | 核对、验证、管理 |

简单类比:
  • 公钥 ≈ 你的身份证原件(需要提交给GitHub)
  • 指纹 ≈ 身份证号码(用于快速识别和核对)
  • 私钥 ≈ 你的签名/印章(用于证明你是你)

结论:指纹是个"校验工具",帮你确认"对的钥匙"放在了"对的锁"上,但它本身不是钥匙。你需要的是公钥本身去GitHub认证,而不是它的指纹。


提交代码 懒得写了复制粘贴的 自己变通吧,提交前先git add .

...or create a new repository on the command line

echo "# navdemo" >> README.md

git init

git add README.md

git commit -m "first commit"

git branch -M main

git remote add origin git@github.com:yumeko2333333/navdemo.git

git push -u origin main

...or push an existing repository from the command line

git remote add origin git@github.com:yumeko2333333/navdemo.git

git branch -M main

git push -u origin main

bash 复制代码
# 懒得编辑了自己看吧
# 实践如此
jh@DESKTOP-885GOSQ:/mnt/e/YumeWorkFiles/Aaaa-t/Abbb-t/A-TestingDemo$ cd navdemo
jh@DESKTOP-885GOSQ:/mnt/e/YumeWorkFiles/Aaaa-t/Abbb-t/A-TestingDemo/navdemo$ git init
Reinitialized existing Git repository in /mnt/e/YumeWorkFiles/Aaaa-t/Abbb-t/A-TestingDemo/navdemo/.git/
jh@DESKTOP-885GOSQ:/mnt/e/YumeWorkFiles/Aaaa-t/Abbb-t/A-TestingDemo/navdemo$ git commit -m "first commit"
On branch main

Initial commit

Untracked files:
  (use "git add <file>..." to include in what will be committed)
        index.html
        linksdata.json
        login.html
        notes.html
        notesdata.json
        ok/
        others/
        recipes.html
        recipes10.html
        recipes9.html
        recipesdata.json
        reminders.json
        version/
        webhook.php

nothing added to commit but untracked files present (use "git add" to track)
jh@DESKTOP-885GOSQ:/mnt/e/YumeWorkFiles/Aaaa-t/Abbb-t/A-TestingDemo/navdemo$ git add .
jh@DESKTOP-885GOSQ:/mnt/e/YumeWorkFiles/Aaaa-t/Abbb-t/A-TestingDemo/navdemo$ git commit -m "first commit"
[main (root-commit) 19cd883] first commit
 21 files changed, 22511 insertions(+)
 create mode 100644 index.html
 create mode 100644 linksdata.json
 create mode 100644 login.html
 create mode 100644 notes.html
 create mode 100644 notesdata.json
 create mode 100644 ok/changeimgcolor.html
 create mode 100644 others/jsex1.html
 create mode 100644 others/mousehightlight.js
 create mode 100644 others/newreminders3.html
 create mode 100644 others/snake1.js
 create mode 100644 recipes.html
 create mode 100644 recipes10.html
 create mode 100644 recipes9.html
 create mode 100644 recipesdata.json
 create mode 100644 reminders.json
 create mode 100644 version/index1.html
 create mode 100644 version/index_testing4.html
 create mode 100644 version/notes1/notes.css
 create mode 100644 version/notes1/notes.js
 create mode 100644 version/notes1/notes1.html
 create mode 100644 webhook.php
jh@DESKTOP-885GOSQ:/mnt/e/YumeWorkFiles/Aaaa-t/Abbb-t/A-TestingDemo/navdemo$ git push -u origin main
Enumerating objects: 27, done.
Counting objects: 100% (27/27), done.
Delta compression using up to 8 threads
Compressing objects: 100% (26/26), done.
Writing objects: 100% (27/27), 120.81 KiB | 798.00 KiB/s, done.
Total 27 (delta 6), reused 0 (delta 0), pack-reused 0
remote: Resolving deltas: 100% (6/6), done.
To github.com:yumeko2333333/navdemo.git
 * [new branch]      main -> main
branch 'main' set up to track 'origin/main'.
jh@DESKTOP-885GOSQ:/mnt/e/YumeWorkFiles/Aaaa-t/Abbb-t/A-TestingDemo/navdemo$
相关推荐
鸿蒙程序媛1 小时前
【工具汇总】git 常用命令行汇总
大数据·git·elasticsearch
虞十三2 小时前
AtomGit 开源入门全攻略:环境搭建 + Git/Docker 实操 + 新手避坑(全平台版)
git·docker·容器
__Witheart__3 小时前
Gitblit 后台删除账户 添加权限
git
回家路上绕了弯3 小时前
IDEA 2026.1 玩转 Git Worktree:可视化操作,告别分支切换内耗
git·后端
wwj888wwj4 小时前
Ansible基础(复习3)
linux·运维·服务器·git·ansible
Slow菜鸟4 小时前
Git Worktree 使用教程
大数据·git·elasticsearch
阿民不加班19 小时前
【Git】git拉取远端但是本地存在不想提交文件处理
git
Selina K20 小时前
在windows安装git
git
LuDvei1 天前
windows x86中ssh远程连接 ubuntu
windows·ubuntu·ssh
周杰伦fans1 天前
如何将 Feature 分支同步到 Master 主分支:一次完整的 Git 合并实战
git