git push命令:
git remote add origin {遠程地址}
git push origin master
新建user1、user2的SSH Key
#新建user1 SSH key:
$ cd ~/.ssh
# 切換到C:\Users\Administrator\.ssh
#ssh-keygen -t rsa -C "[email protected]"
一路回車即可;
# 新建user2的SSH key
#ssh-keygen -t rsa -C "[email protected]"
# 設置名稱爲Enter file in which to save the key (/c/Users/Administrator/.ssh/id_rsa): /c/Users/Administrator/.ssh/id_rsa_user2
接下來一路回車不設置密碼
密鑰添加到SSH agent中
因爲默認只讀取id_rsa,爲了讓SSH識別新的私鑰,需將其添加到SSH agent中:
ssh-add ~/.ssh/id_rsa_user2
如果出現Could not open a connection to your authentication agent的錯誤,就試着用以下命令:
eval `ssh-agent -s`ssh-add ~/.ssh/id_rsa_user2
將ssh key 添加到github賬號中
clip< ~/.ssh/id_rsa_user2.pub 拷貝sshkey到剪切板
打開github網頁,添加ssh key,複製進去。
修改config文件
在~/.ssh目錄下找到config文件,如果沒有就創建:
touch config
然後修改我的config配置如下:
Host github.comHostName github.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa
Host github2
HostName github.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa_user2
測試
$ ssh -T [email protected]
Hi XXXX! You've successfully authenticated, but GitHub does not provide shell access.
$ ssh -T git@github2
Hi XXXX! You've successfully authenticated, but GitHub does not provide shell access.
--------------------------PS ---------------------
用以上方法成功使用上了自己的Github賬號clone項目,但是兩條都提示的是我自己的賬號,明明設置了其中一個是工作賬號的。。。。不過好在工作賬號也沒啥需要訪問上去的必要。