2012年11月5日 星期一

Git多帳號登入

在使用GitHub或BitBucket服務時,使用ssh登入是最快的方式
要如何在一台電腦上使用不同的帳號登入
一.產生各自帳號的SSH Key
執行
ssh-keygen -C "youremail@xxx"
預設會儲存為id_rsa 的key,不同的email產生key請設定使用不同檔名儲存

二設定ssh config
在~/.ssh/目錄下產生config檔
在config內設定不同host指定使用不同的ssh key

Host PeterBitbucket
HostName bitbucket.org
User git
IdentityFile ~/.ssh/peter_id_rsa
IdentitiesOnly yes

Host OzzyBitbucket
HostName bitbucket.org
User git
IdentityFile ~/.ssh/ozzy_id_rsa
IdentitiesOnly yes

三.設定remote
在要使用的git repos設定remote
原本設定
git remote add git@bitbucket.org:ozzy/myrepos.git
改用以下方式設定
git remote add OzzyBitbucket:ozzy/myrepos.git
另一個帳號
git remote add PeterBitbucket:peter/myrepos.git
讓不同的帳號使用不同的ssh key連線

沒有留言: