收到一封郵件,準(zhǔn)確的說(shuō),是第二次還是第三次收到了。GitHub發(fā)過(guò)來(lái)的枷颊,標(biāo)題是:
[GitHub] Deprecation Notice
Hi @hooman118,
You recently used a password to access the repository at hooman118/hoo-wiki with git using git/2.21.0 (Apple Git-122).
Basic authentication using a password to Git is deprecated and will soon no longer work. Visit https://github.blog/2020-12-15-token-authentication-requirements-for-git-operations/ for more information around suggested workarounds and removal dates.
Thanks,
The GitHub Team
點(diǎn)開(kāi)鏈接一看,原來(lái)果然是去年底就公告了该面。要求以后命令行或者第三方API都改成Token而不是密碼夭苗。這樣當(dāng)然更安全啦,但是我一直懶得改隔缀,畢竟一直能用题造。不過(guò)呢,2021年8月13號(hào)以后猾瘸,命令行就再也不允許使用密碼了界赔。還是早點(diǎn)折騰下吧丢习。
好在GitHub的幫助寫(xiě)得是非常清晰,照著做很快就搞定了淮悼。只需三步:
- 創(chuàng)建個(gè)人Token
- 確保Git緩存了你的認(rèn)證信息
- 把緩存的認(rèn)證信息修改成Token
1. 創(chuàng)建個(gè)人Token
Git的幫助在這里Creating a personal access token咐低,非常清晰。
確保郵件地址已經(jīng)驗(yàn)證過(guò)了袜腥。
-
登陸GitHup主頁(yè)见擦,在右上角,點(diǎn)自己Profile的頭像羹令,再點(diǎn)擊Settings鲤屡。
image -
在左邊的菜單里,點(diǎn)擊Developer Settings
image -
繼續(xù)在左邊的菜單里福侈,找到并點(diǎn)擊Personal Access Token
image 點(diǎn)擊Generate New Token
-
給個(gè)名字酒来,描述這個(gè)Token的用途
image 選擇權(quán)限,如果是用于命令行癌刽,選 repo即可
- 最后點(diǎn)擊Generate Token這個(gè)按鈕
-
點(diǎn)擊??圖標(biāo)把Token拷貝出去備用役首。切記,因?yàn)榘踩颍?strong>若此時(shí)不拷貝显拜,離開(kāi)這頁(yè)后就再也看不到它了。
image
注意咯爹袁,從此后远荠,你的Git命令行,就只能用https失息,而不能用SSH了譬淳。因?yàn)镻ersonal Access Token只能用于https……
2. 確保Git緩存了你的認(rèn)證信息
Git幫助原文在這里Caching your GitHub credentials in Git。
我用的是Mac盹兢,只驗(yàn)證了Mac上的操作方法邻梆,需要了解在其他操作系統(tǒng)上怎么弄,請(qǐng)看Git幫助原文绎秒。
-
確保Git 和
osxkeychain helper
已經(jīng)安裝浦妄,在命令行敲入以下命令,看看是不是會(huì)出使用幫助见芹。$ git credential-osxkeychain # Test for the cred helper > Usage: git credential-osxkeychain <get|store|erase>
-
如果剂娄,
osxkeychain helper
沒(méi)裝好,你會(huì)看到下面的提示玄呛,讓你安裝Xcode 命令行工具:$ git credential-osxkeychain > xcode-select: note: no developer tools were found at '/Applications/Xcode.app', > requesting install. Choose an option in the dialog to download the command line developer tools.
或者阅懦,你可以用Homebrew來(lái)安裝Git 和
osxkeychain helper
,如下:$ brew install git
-
告訴Git徘铝,使用
osxkeychain helper
來(lái)做全局的credential.helper
配置耳胎,如下:$ git config --global credential.helper osxkeychain # Set git to use the osxkeychain credential helper
3. 把認(rèn)證信息修改成Token
這部分的幫助原文在這里Updating credentials from the macOS Keychain惯吕。有兩種方法:
- 用Keychain Access來(lái)刪除或修改
- 用命令行來(lái)刪除
我是用第一種辦法搞定的,非常簡(jiǎn)單怕午。
- 首先混埠,用Spotlight找到Keychain Access并運(yùn)行(慚愧,我是第一次這么用Spotlight)
在Keychain Access里诗轻,找到github.com
雙擊钳宪,勾選下面那個(gè)show password
把Password 替換為之前復(fù)制的那個(gè)Personal Access Token
保存,大功告成扳炬!
這些技術(shù)性的小玩意吏颖,不知放到哪個(gè)類別,暫時(shí)也歸入?yún)^(qū)塊鏈一類吧恨樟。畢竟我是因?yàn)樽鰠^(qū)塊鏈的項(xiàng)目重新開(kāi)始玩git hub的半醉,雖然,現(xiàn)在拿這把牛刀劝术,也只不過(guò)用來(lái)存每天日更的文章而已缩多。