- 查找已經(jīng)存在的SSH KEY
ls -al ~/.ssh
- 生成一個(gè)key
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 (/your_home_path/.ssh/id_rsa):
這里注意如果以前已經(jīng)生成過sshkey日熬,文件名為"id_rsa",如果不 想覆蓋的話需要在后面輸入新的文件名,如:"id_rsa2"
Enter passphrase (empty for no passphrase): [Type a passphrase]
Enter same passphrase again: [Type passphrase again]
如果需要設(shè)置密碼則自己填入
- 將key加入到ssh-agent中
$ ssh-add -l
Could not open a connection to your authentication agent.
如果發(fā)現(xiàn)上面的提示,說明系統(tǒng)代理里沒有任何key,執(zhí)行如下操作
exec ssh-agent bash
如果系統(tǒng)已經(jīng)有ssh-key 代理 归露,將.ssh目錄下的密鑰添加到ssh-agent中
$ ssh-add ~/.ssh/id_rsa
$ ssh-add ~/.ssh/id_rsa2
......
- 在.ssh中創(chuàng)建config配置文件
nano ~/.ssh/config
或者可以直接創(chuàng)建config文件,再打開編輯
open ~/.ssh/config
- 輸入配置信息
#id_rsa (某github 配置)
Host git@github.com:xxxxx
HostName git@github.com:xxxxx
User git
IdentityFile ~/.ssh/id_rsa
#id_rsa2 (另一個(gè)github配置)
HostName git@github.com:xxxxx
User git
dentityFile ~/.ssh/id_rsa2
...
多個(gè)SSH帳號(hào)配置完成以后救崔,如果需要改動(dòng)某工程的.git
文件中的遠(yuǎn)程url囤耳,cd ~/xxx/.git
打開config
文件,將remote origin
的url前段修改為你設(shè)置的Hostname即可面褐。
如 url = git@github.com:xxxxx/xxx.git