轉自我的博客,轉載請聲明,走啊走的記錄:設置 SSH 使用 hexo deploy 時免輸用戶名密碼git
此篇博客日期 2016-05-14
,使用 hexo v0.2.0
。介紹清楚這個使用背景是由於網上的有些教程已通過時,至少當我徹底按照那些步驟來設置的時候並無成功。SSH 驗證就是咱們鍵入命令 hexo deploy
之後,當那些須要提交的內容顯示完成事後會彈出的一個小窗口提示咱們輸入用戶名、密碼。我參考了網上的一些教程,如今給出完整可行的教程,let's do it!github
首先打開命令行工具,一般咱們能夠直接右鍵鼠標任意位置打開 Git Bash Here
,而後輸入如下命令shell
$ cd ~/.ssh # Checks to see if there is a directory named ".ssh" in your user directory
使用 ssh-keygen
生成密鑰json
$ ssh-keygen -t rsa -C "your_email@example.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,接下來顯示以下hexo
Enter passphrase (empty for no passphrase): [Type a passphrase] Enter same passphrase again: [Type passphrase again]
按提示輸入密碼便可(簡化流程的話在鍵入命令 ssh-keygen -t rsa -C "your_email@example.com"
之後的三次提示輸入均可以直接回車跳過)。ssh
密鑰生成成功ide
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: …………………此處是密鑰內容…………………… your_email@example.com
能夠選擇是在用戶設置中添加密鑰(Settings --> SSH GPG keys)仍是單個項目中添加密鑰,在這裏我就在咱們的博客項目中添加密鑰,此處以個人博客爲例。
在 chengjianhua.github.io
的首頁菜單欄中點擊 Settings --> Deploy keys --> Add deploy key,而後將生成的 id_rsa.pub
中的內容全選複製到 key 輸入框中,而後點擊 Add key 完成添加公鑰。工具
接下來測試配置是否成功測試
$ ssh -T git@github.com
若是出現如下內容即表示配置完成而且成功!fetch
Hi username! You've successfully authenticated, but GitHub does not provide shell access.
到了這一個步驟和你們在網上搜到的其餘教程就不同了,網上的這一步就是設置
# 切入到包含 .git 文件夾的文件夾 $ cd .deploy/ # 查看當前的傳輸協議 $ git remote -v origin https://github.com/USERNAME/REPOSITORY.git (fetch) origin https://github.com/USERNAME/REPOSITORY.git (push) # 修改 https 協議爲 ssh 協議 $ git remote set-url origin git@github.com:USERNAME/REPOSITORY2.git
可是我根據網上的並無用。更別提個人 blog 文件夾中包含 .git
文件夾的文件夾(好繞啊……)名字是 .deploy_git
了。還有我輸入 $ git remote -v
時的顯示結果爲空,我嘗試過本身添加 $ git remote add origin git@github.com:chengjianhua/chengjianhua.github.io.git
,而後 $ hexo deploy
仍是須要輸入密碼。
解決辦法出來了!
在 hexo deploy
的控制檯輸出結果中我看到了連接仍然是 https
的連接,這時我想到了 hexo
的配置文件 _config.yml
中的 deploy
屬性。
deploy: type: git repo: git@github.com:chengjianhua/chengjianhua.github.io.git branch: master
我將其中的 repo
修改爲了git@github.com:chengjianhua/chengjianhua.github.io.git
,這個時候我再嘗試了 $ hexo deploy
果真成功了,就不用輸入密碼了!
到此個人解決方法已經完成了,但願能幫到使用 hexo
的同窗們~