創建git密鑰


前言

git使用https協議,每次pull,push都要輸入密碼,使用git協議,使用ssh秘鑰,可以省去每次輸密碼

大概需要三個步驟:

一、本地生成密鑰對;

二、設置github上的公鑰;

三、修改git的remote url為git協議。


生成密鑰

$ ssh-keygen -t rsa -C “your_email@youremail.com“
 
Creates a new ssh key using the provided email # Generating public/private rsa key pair.
 
Enter file in which to save the key (/home/you/.ssh/id_rsa):
 
直接Enter就行。然后,會提示你輸入密碼,如下(建議輸一個,安全一點,當然不輸也行):
 
Enter passphrase (empty for no passphrase): [Type a passphrase]
 
Enter same passphrase again: [Type passphrase again]

然后會提示你,你的密鑰在哪

Your identification has been saved in /home/you/.ssh/id_rsa.
 
Your public key has been saved in /home/you/.ssh/id_rsa.pub.
 
The key fingerprint is: # 01:0f:f4:3b:ca:85:d6:17:a1:7d:f0:68:9d:f0:a2:db your_email@youremail.com
]

添加公鑰到你的github帳戶

1.復制密鑰

$ cat ~/.ssh/id_rsa.pub

如果你是windows用戶,那么請在你的用戶目錄下,找到.ssh文件夾然后打開id_rsa.pub直接復制就可以了

2、登陸你的github帳戶。然后 Account Settings -> 左欄點擊 SSH Keys -> 點擊 Add SSH key

3、然后你復制上面的公鑰內容,粘貼進“Key”文本域內。 title域,你隨便填一個都行。

4、完了,點擊 Add key。

這樣,就OK了。然后,驗證下這個key是不是正常工作。

$ ssh -T git@github.com

會提示你:

Hi username! You’ve successfully authenticated, but GitHub does not # provide shell access.

這就大功告成!


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM