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中.

第三條:提示成功

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章