天天看點

Git使用之Permission Denied問題解決

今天碰到了git的permission denied問題。

在安裝好git之後,我們一般會配置使用者名和郵箱

git config --global user.name "zengjinlong" #--global表明本機的所有git倉庫均使用該配置

  git config --global user.email "[email protected]"  

但是當我們克隆一個庫的時候,發現不論你怎麼輸入密碼都是說permission denied。

其實,這是你沒有生成公鑰

找到這個頁面:

ssh keys

ssh key allows you to establish a secure connection between your computer and gitlab

before generating an ssh key, check if your system already has one by running cat ~/.ssh/id_rsa.pub if your see a long string starting with ssh-rsa or ssh-dsa, you can skip the ssh-keygen step.

to generate a new ssh key just open your terminal and use code below. the ssh-keygen command prompts you for a location and filename to store the key pair and for a password. when prompted for the location and filename you can press enter to use the default.

it is a best practice to use a password for an ssh key but it is not required and you can skip creating a password by pressing enter. note that the password you choose here can't be altered or retrieved.

ssh-keygen -t rsa -c "$your_email"

use the code below to show your public key.

cat ~/.ssh/id_rsa.pub

copy-paste the key to the 'my ssh keys' section under the 'ssh' tab in your user profile. please copy the complete key starting with ssh- and ending with your username and host.

很簡單,就是用你的郵箱生成一個公鑰,然後加入到你的代碼管理網站中。然後在如下頁面中加入ssh key到項目中。

<a target="_blank" href="http://gitlab.urd.com/profile/keys/new">add ssh key</a>

ssh keys allow you to establish a secure connection between your computer and gitlab 

然後再git clone 一次,發現可以了。好了。這個問題解決。