如何将 git 远程 URL 从 https 更改为 ssh

在项目开发中,使用 SSH 连接 Git 仓库可以提高安全性和便利性。本文将指导你如何将 Git 远程 URL 从 HTTPS 更改为 SSH。

操作指南

步骤 1: 查看当前远程 URL

首先,确认当前的远程 URL 使用的是 https。打开终端并输入以下命令:

git remote -v

如:

origin https://github.com/username/repo.git (fetch)

origin https://github.com/username/repo.git (push)

步骤 2: 修改远程 URL 为 SSH

使用以下命令将远程 URL 更改为 ssh:

git remote set-url origin git@github.com:username/repo.git

步骤3:配置 ssh 密钥

检查本地 ssh 密钥

ls ~/.ssh

如果没有,生成一个新的

ssh-keygen -t rsa -b 4096 -C "your_email@example.com"

复制 ssh 公钥到 github

cat ~/.ssh/id_rsa.pub

相关推荐
Avan_菜菜2 小时前
FRP 内网穿透完整实战:从 HTTP 映射到 HTTPS 自签代理
运维·nginx·https
叫我少年6 小时前
Windows 中安装 git
git
SelectDB1 天前
Litefuse 开源并推出单进程轻量模式,25 秒就能跑起来的 Agent 可观测与评估平台
运维·后端·自动化运维
XIAOHEZIcode2 天前
Linux系统鼠标偏移常见原因以及修复方案
linux·运维·游戏
用户0328472220703 天前
如何搭建本地yum源(上)
运维
深海鱼在掘金5 天前
Git 完全指南 —— 第1章:Git 概览与版本控制演进
git
大树886 天前
金刚石散热越强,管路越先见顶
大数据·运维·服务器·人工智能·ai
摇滚侠6 天前
Linux CentOS7 rpm 安装 MySQL 5.7
linux·运维·mysql
霸道流氓气质6 天前
领域驱动设计(DDD)在 Spring Boot 微服务中的实践指南
运维·spring boot·微服务
开发者联盟league6 天前
安装pnpm
ssh