工作中會遇見需要在一個mac上添加多個git賬號,mac添加多個git ssh步驟:
首先打開終端 輸入命令行
cd .ssh 進入.ssh路徑下
然后輸入命令行
ssh-keygen -t rsa -C "***@***.com"
創(chuàng)建新的rsa 終端會提示你輸入新的rsa名字,id_rsa_*(輸入你要創(chuàng)建的ssh名字)
之后會讓輸入密碼
成功后就會在.ssh下生產(chǎn)id_rsa_*和id_rsa_*.pub兩個文件
輸入命令行
cat ~/.ssh/id_rsa_*.pub
復制ssh粘貼到github 的ssh中,添加
之后在mac終端輸入命令行
ssh-add -K ~/.ssh/id_rsa_*添加ssh到本地
在.ssh下創(chuàng)建config文件
touch config
open config 打開文件輸入
#github
Host github.com
HostName github.com
User ***@***.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa_*(需要配置所有的rsa )保存
ps:我的mac不知道為什么突然git 的ssh失效了,用命令行可以push,pull,但是用AS自帶的git 工具不能push,pull,報could not read from remote repository.記錄下解決方法?
1.在AS的Preferences中找到version control ,設置git? 的ssh executable 為native
2,用命令行cd 到.ssh 目錄下,使用ssh-add id_rsa 重新加下ssh