1.查看当前是否存在sshgit
ls ~/.ssh/
看到 id_rsa 与 id_rsa_pub 则说明已经有一对密钥。
2.生产新的公钥,并命名它不于以前的冲突github
ssh-keygen -t rsa -f ~/.ssh/id_rsa_2 -C "yourmail@xxx.com"
3.配置sshKey对应的Hostshell
vim ~/.ssh/config
根据实际的Host修改文件,例若有github和ieit两个Host,则像以下方式修改
# default Host github.com HostName github.com User git IdentityFile ~/.ssh/id_rsa # two Host ieit.github.com HostName github.com User git IdentityFile ~/.ssh/id_rsa_2
4.复制新生成的ssh-key,去相应的地方配置vim
pbcopy < ~/.ssh/id_rsa.pub
5.测试是否成功ssh
ssh -T git@yourhost.com
收到入下信息表示配置成功
The authenticity of host 'github.com (192.30.255.112)' can't be established. RSA key fingerprint is SHA256:sdfsxxxxxxxxxxxxxxxxxxx. Are you sure you want to continue connecting (yes/no)? yes Warning: Permanently added 'github.com,192.30.255.112' (RSA) to the list of known hosts. Hi gsbybb! You've successfully authenticated, but GitHub does not provide shell access.
6.克隆repo
7.取消全局 用户名/邮箱设置,并进入项目文件夹单独设置ide
git config --global --list //查看全局设置 git config user.name "yourname" git config user.email "your@email.com"
8.命令行进入项目目录,重建 origin测试
git remote rm origin git remote add origin git@ieit.github.com
9.成功,能够 push 测试一下命令行