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

相关推荐
君穆南6 小时前
基于 NFS 与 Rsync 实现跨服务器 Seafile 数据平滑迁移实战
linux·运维·git
bloglin999996 小时前
scp、rsync远程文件同步
linux·运维·服务器
迦南的迦 亚索的索7 小时前
LINUX环境
linux·运维·服务器
yuanjj887 小时前
linux下调试域格CLM920 NC5等9x07平台模块 QMI拨号
linux·运维·服务器
IMPYLH7 小时前
Linux 的 printenv 命令
linux·运维·服务器·bash
SilentSamsara7 小时前
SSH 远程管理:密钥登录 + 隧道转发,一次性配置好
linux·运维·服务器·ubuntu·centos·ssh
Jurio.7 小时前
本机开发 + 多机执行的极简远端运行工具
linux·git·python·github·远程工作
阿巴~阿巴~8 小时前
Git版本控制完全指南:从入门到实战(简单版)
linux·服务器·git
Cx330❀8 小时前
Linux命名管道(FIFO)通信:从原理到实操,一文搞懂跨进程通信
大数据·linux·运维·服务器·elasticsearch·搜索引擎
遇满则缺8 小时前
新手第一次使用gitee全流程(附上常见错误以及解决方法)
git·gitee