一,安装ssh-keygen ,方便给本地授权生成私密钥
Windows 安装 ssh-keygen 的完整步骤
安装 OpenSSH 客户端
-
通过 Windows 设置安装
-
- 适用于 Windows 10/11:
- 打开 设置 → 应用 → 可选功能 → 添加功能。
- 在列表中找到 OpenSSH 客户端,勾选后点击 安装18。
- 适用于 Windows 10/11:
-
通过 PowerShell 命令安装(管理员权限)
powershellCopy CodeAdd-WindowsCapability -Online -Name OpenSSH.Client~~~~0.0.1.0
-
- 安装完成后,重启系统24。
验证 SSH 客户端安装
- 检查 ssh-keygen 是否可用
bashCopy Codessh-keygen --version
-
- 若显示版本信息(如 OpenSSH_xx.x),则安装成功18。
生成 SSH 密钥对
-
执行密钥生成命令
bashCopy Codessh-keygen -t rsa -b 4096 -C "your_email@example.com"
-
- -t rsa:指定密钥类型为 RSA。
- -b 4096:设置密钥长度为 4096 位(安全性更高)57。
-
配置密钥保存路径
-
- 默认路径:C:\Users\\.ssh\id_rsa。
- 建议直接按回车使用默认路径78。
-
设置密钥密码(可选)
-
- 输入密码短语(用于保护私钥),或留空直接按两次回车跳过57。
定位生成的密钥文件
- 公钥文件:C:\Users\\.ssh\id_rsa.pub。
- 私钥文件:C:\Users\\.ssh\id_rsa。
- 公钥需上传到远程服务器(如 Gitea/GitHub)的 SSH 配置中47。
二.找到远程库链接。 在本地执行 git clone 远程库
克隆仓库(首次操作)
git clone # 例如 git clone https://xxxx:3000/weixiaotong/xxxx.git:ml-citation{ref="4,5" data="citationList"}
进入仓库目录
cd # 例如 cd shop-vue:ml-citation{ref="4,5" data="citationList"}
查看所有远程分支
git branch -r # 显示以 origin/ 开头的远程分支列表:ml-citation{ref="6,7" data="citationList"}
创建并切换到新分支
git checkout -b origin/ # 例如 git checkout -b dev origin/dev:ml-citation{ref="6,7" data="citationList"}
拉取最新代码
git pull # 由于已关联远程分支,可直接拉取:ml-citation{ref="6,8" data="citationList"}