文章目录

创建ssh key
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
ssh-keygen -t rsa -f ~/.ssh/id_rsa.github -C "5868037@qq.com" Generating public/private rsa key pair. Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /Users/xx/.ssh/id_rsa.github. Your public key has been saved in /Users/xx/.ssh/id_rsa.github.pub. The key fingerprint is: SHA256:iAGxx/qbZgxz2T1unhAiLaE 5868037@qq.com The key's randomart image is: +---[RSA 2048]----+ |**o.. | |O.o+. | | =o+. | |..+.=o.. | |oE+B.=+.S | |o+.+*o...o | |+ .= .. . | |. .+. .o. | | o+. oo | +----[SHA256]-----+ |
创建config文件
1 2 3 |
cd ~/.ssh touch config open config |
配置config(示例)
1 2 3 4 |
Host github HostName github.com User xxx IdentityFile ~/.ssh/id_rsa.github |
将ssh-key添加到ssh-agent
(1)到上面这一步我们已经创建好了 ssh-key,此时还需要将新的 ssh-key 添加到ssh agent ,因为默认只读 id_rsa,首先查看一下已经添加进去的 ssh-key,当出现下面 这种情况是说明 ssh agent 里面并没有把我们新生产的 ssh-key添加进去
1 2 |
➜ ssh-add -l The agent has no identities. |
(2)可以选择把我们生成的 ssh-key 添加进去,也可以指定添加
1 2 3 4 5 6 |
//全部添加 ssh-add //指定添加(可以切换到.ssh下添加,也可以直接指定路径添加) ➜ .ssh ssh-add id_rsa.github Enter passphrase for id_rsa.github: Identity added: id_rsa.github (iid_rsa.github) |
(3)这时输入下面指令就能看见我们添加进去的 ssh-key
1 |
ssh-add -l |
测试一下是否成功
1 |
ssh -T git@github.com |
显示如下表示成功:Hi (你的github帐号名)! You've successfully authenticated, but GitHub does not provide shell access.
修改项目的git配置
1 2 |
cd 你的项目 open .git/config |
按照如下修改
1 2 3 |
// 找到url,把等号后面的 git@github.com替换成你配置的host,上面配置的为github,感叹号后面不变 url = git@github.com:... // 修改前 url = github:... // 修改后 |
1 2 |
amend命令只会修改最后一次commit的信息 git commit --amend --reset-author |
