要解决使用SSH连接GitHub时一直提示输入密码的问题,可以按照以下步骤进行操作:
-
检查SSH密钥是否存在:在终端中输入
ls -al ~/.ssh
来查看是否存在 SSH 密钥,通常会显示为id_rsa
和id_rsa.pub
。 -
生成新的 SSH 密钥:如果在上一步中没有找到 SSH 密钥,可以使用以下命令生成新的 SSH 密钥:
ssh-keygen -t rsa -b 4096 -C "[email protected]"
,其中[email protected]
需要替换为你的 GitHub 邮箱。 -
添加 SSH 密钥到 GitHub:使用以下命令将公钥添加到 GitHub 上:
pbcopy < ~/.ssh/id_rsa.pub
然后登录到 GitHub 上的账户,点击右上角的头像,选择 "Settings" -> "SSH and GPG keys",点击 "New SSH key",将剪贴板中的 SSH 公钥粘贴到 "Key" 字段中,并给该 SSH 密钥起一个名称。
-
设置本地 Git 配置:在终端中输入以下命令以设置本地 Git 配置:
git config --global user.email "[email protected]" git config --global user.name "Your Name"
-
更改远程仓库为 SSH:如果已经使用 HTTPS 克隆了远程仓库,需要将其更改为 SSH。在终端中使用以下命令更改远程仓库地址:
git remote set-url origin [email protected]:username/repo.git
其中
username
是你在 GitHub 上的用户名,repo
是你的仓库名称。
现在,你应该能够使用 SSH 连接到 GitHub 而无需输入密码了。