MAC下配置ssh让SourceTree通过秘钥访问远程仓库

问题描述

之前一直使用的 SourceTree 来推送的代码到 gitee 仓库的突然一天不能推送了,说是没有权限,确认过本地生成 rsa 公钥加入了仓库 ssh 配置,所以直接执行第四步,解决问题;

由于TortoiseGit没有MAC版本,我们使用了SourceTree来替代.

在帮同事解决Mac下的Git的时候,碰到一个问题:

sh-3.2# git clone [email protected]:windss/accounting_tool_products.git
Cloning into 'accounting_tool_products'...
[email protected]: Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

解决步骤

  1. 在用户目录下创建.ssh文件夹—已有则跳过

  2. 生成公钥和私钥

命令:ssh-keygen -t rsa -C '[email protected]' -f ~/.ssh/gitee_id_rsa
  1. 创建cofig文件(任意名称),存放以下内容
Host mygit
HostName   host
Port       22
User       git
IdentityFile ~/.ssh/gitee_id_rsa
  1. 将私钥加入ssh
sh-3# export PATH=/usr/bin:$PATH
sh-3# ssh-add -K ~/.ssh/gitee_id_rsa
Identity added: /var/root/.ssh/gitee_id_rsa ([email protected])

第一条:将当前的环境变量设置成user/bin,进入/user/bin目录.

第二条:将密钥加到ssh中.

第三条:提示成功

你可能感兴趣的:(git,gitee,sourcetree)