如何将 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

相关推荐
冠希陈、21 小时前
云锁客户端连不上服务器处理
linux·运维·服务器
做运维的阿瑞21 小时前
Linux 企业级备份体系实战:cron/anacron/restic/rclone 对比与脚本总结
linux·运维·服务器·后端·学习·系统架构·centos
ziyue757521 小时前
idea终端添加git-bash,支持linux的shell语法
linux·git·bash·idea·软件
wanhengidc21 小时前
BGP高防服务器具体是指什么
运维·服务器·网络·安全·游戏·智能手机
2301_7679026421 小时前
10. Linux 系统启动原理
linux·运维·服务器
zrande21 小时前
Linux 脚本实现[联网才工作]:拒绝离线分析的实用方案
运维·联网检测
☆璇21 小时前
【Linux】Ext系列文件系统(下)
linux·运维·服务器
crackpot·21 小时前
Linux 命令
linux·运维·服务器
所念皆为东辞21 小时前
服务器时间同步校准
linux·运维·服务器
wanhengidc1 天前
云手机性能会受到哪些因素的影响?
运维·服务器·网络·游戏·智能手机