设置一个自定义名称的密钥,用于 git 仓库上下传使用

在 Windows 上为 Git 仓库设置自定义名称的 SSH 密钥教程

1. 生成自定义名称的 SSH 密钥

打开 Git Bash(在开始菜单中搜索或在任意文件夹内右键选择)。

执行以下命令,并将 your_email@example.com 替换为你的邮箱地址,custom_key_name 替换为你想要的自定义密钥文件名。

codeBash

复制代码
ssh-keygen -t rsa -b 4096 -C "your_email@example.com" -f ~/.ssh/custom_key_name
2. 将新的 SSH 密钥添加到 SSH-Agent

首先,启动 SSH-Agent。

codeBash

复制代码
eval $(ssh-agent -s)

然后,添加你刚刚生成的私钥。

codeBash

复制代码
ssh-add ~/.ssh/custom_key_name
3. 配置 SSH 以使用新的密钥

在 ~/.ssh/ 目录下创建一个名为 config 的文件(如果不存在的话)。

打开 config 文件并添加以下内容。将 custom_host 替换为一个自定义别名(例如 github-custom),将 HostName 替换为你的 Git 仓库托管服务商的域名(例如 github.com),并将 IdentityFile 的路径指向你的私钥文件。

codeCode

复制代码
Host custom_host
    HostName github.com
    User git
    IdentityFile ~/.ssh/custom_key_name
4. 将公钥添加到你的 Git 仓库托管平台

复制你的公钥内容。

codeBash

复制代码
clip < ~/.ssh/custom_key_name.pub

登录到你的 Git 仓库托管平台(如 GitHub、GitLab 等),进入 "Settings" -> "SSH and GPG keys",点击 "New SSH key",将复制的公钥粘贴进去并保存。

5. 配置本地 Git 仓库使用新的密钥

对于一个新的仓库,使用你自定义的 Host 来克隆。

codeBash

复制代码
git clone git@custom_host:USERNAME/REPOSITORY.git

对于一个已存在的仓库,更新其远程仓库 URL。

codeBash

复制代码
git remote set-url origin git@custom_host:USERNAME/REPOSITORY.git
相关推荐
开开心心就好11 小时前
开源免费高速看图工具,支持漫画大图秒开
linux·运维·服务器·安全·ruby·symfony·1024程序员节
unable code3 天前
磁盘取证-Flying_High
网络安全·ctf·misc·1024程序员节·磁盘取证
unable code4 天前
磁盘取证-ColorfulDisk
网络安全·ctf·misc·1024程序员节·内存取证
unable code5 天前
磁盘取证-[第十章][10.1.2 磁盘取证方法]磁盘取证1
网络安全·ctf·misc·1024程序员节·内存取证
开开心心就好7 天前
免费抽奖工具支持批量导入+自定义主题
linux·运维·服务器·macos·pdf·phpstorm·1024程序员节
开开心心就好11 天前
卸载工具清理残留,检测垃圾颜色标识状态
linux·运维·服务器·python·安全·tornado·1024程序员节
子燕若水12 天前
Facebook reels 运营指南
1024程序员节
尘觉15 天前
创作 1024 天|把热爱写成长期主义
数据库·1024程序员节
写点什么呢16 天前
Word使用记录
word·1024程序员节
开开心心就好16 天前
内存清理工具点击清理,自动间隔自启
linux·运维·服务器·安全·硬件架构·材料工程·1024程序员节