新增多個SSH key之後驗證失敗

2021-06-21 13:05:42 字數 2055 閱讀 9219

git賬戶生成了多個ssh key之後總是驗證不過,一直用的老的ssh key

initialized empty git repository in***

the authenticity of host '[gerrit.ericsson.se]:29418 ([142.133.164.50]:29418)' can't be established.

rsa key fingerprint is 0d:31:2e:57:bf:29:36:02:04:81:12:85:fd:b8:87:3b.

are you sure you want to continue connecting (yes/no)? yes

warning: permanently added '[gerrit.ericsson.se]:29418,[142.133.164.50]:29418' (rsa) to the list of known hosts.

agent admitted failure to sign using the key.

permission denied (publickey).

fatal: the remote end hung up unexpectedly

解決方法:

ssh-add ~/.ssh/id_rsa

之後就可以了。

github使用ssh與客戶端連線。如果是單使用者(first),生成金鑰對後,將公鑰儲存至github,每次連線時ssh客戶端傳送本地私鑰(預設~/.ssh/id_rsa)到服務端驗證。單使用者情況下,連線的伺服器上儲存的公鑰和傳送的私鑰自然是配對的。但是如果是多使用者(first,second),我們在連線到second的帳號時,second儲存的是自己的公鑰,但是ssh客戶端依然傳送預設私鑰,即first的私鑰,那麼這個驗證自然無法通過。不過,要實現多帳號下的ssh key切換在客戶端做一些配置即可。

首先cd到~/.ssh 使用 ssh-keygen -t -rsa -c 『[email protected]』 生成新的ssh key:id_rsa_second,生成完後將新的ssh public key新增到github。

ssh-keygen -t rsa -c'[email protected]'
預設ssh只會讀取id_rsa,所以為了讓ssh識別新的私鑰,需要將其新增到ssh agent

ssh-add ~/.ssh/id_rsa_second
該命令如果報錯:could not open a connection to your authentication agent.無法連線到ssh agent,可執行ssh-agent bash命令後再執行ssh-add命令。

完成以上步驟後在~/.ssh目錄建立config檔案,該檔案用於配置私鑰對應的伺服器。內容如下:

# default github user([email protected])

host github.com

hostname github.com

user git

identityfile c:/users/username/.ssh/id_rsa

# second user([email protected])

host github-second

hostname github.com

user git

identityfile c:/users/username/.ssh/id_rsa_second

host隨意即可,方便自己記憶,後續在新增remote是還需要用到。

git remote add test git@github-second:second/test.git #並非原來的[email protected]:second/test.git
這樣每次連線都會使用id_rsa_second與伺服器進行連線。至此,大功告成!

注意:github根據配置檔案的user.email來獲取github帳號顯示author資訊,所以對於多帳號使用者一定要記得將user.email改為相應的email([email protected])。

表單新增多個檔案

其實方法很簡單這樣只能選擇乙個檔案,這樣就可以選擇多個檔案了,怎麼樣,很方便吧。如果不考慮ie的話,可以使用這個方法。關於js自行生成多個input的就算了吧,懶得看,懶的寫,能簡單就簡單吧。對了,還有乙個重要的問題,選擇多個檔案以後,如何用jquery獲取選中的檔案的標題等屬性呢?jquery好像...

wamp新增多個埠 多個站點

1 確保http.conf 開啟了 以下類似的服務 有可能搜尋不到 先不管 2 在http.conf中監聽下面專案可能用到的埠如 listen 8083 listen 8082 3 在conf extra httpd vhosts.conf 中新增配置 servername localhost do...

WampServer新增多個php版本

wampserver可以讓開發者在windows系統下快速搭建wamp環境,它支援多版本的apache mysql php之間的相互切換,互不影響,對於phper開發者來講極為方便快速。以下是在wampserver下同時支援php5.3 php5.4 php5.5 php5.6的步驟 1 安裝wam...