github配置ssh 访问

1. 生成公钥和私钥

Linux进入.ssh文件夹:cd ~/.ssh,新建config文件:touch config;或者:touch ~/.ssh/config。这里要注意,没有.ssh文件夹的要新建一个.ssh名的文件夹。

1.1 使用ssh-******

steven$ ssh-****** -t RSA -f id_rsa_github

steven$ ls
id_rsa_github id_rsa_github.pub

生产了id_rsa_github和id_rsa_github.pub

1.2 配置config

Host github.com
HostName github.com
User [email protected]
PreferredAuthentications publickey
IdentityFile /home/Workspace/ssh/id_rsa_github
Host gitlib.com
HostName gitlib.com
User [email protected]
PreferredAuthentications publickey
IdentityFile id_rsa_gitlib

HostName是服务器的地址,User是用户名,PreferredAuthentications照抄即可,这里主要说的是IdentityFile

1.3 添加ssh-agent

$ssh-add id_rsa_github

1.4 设置帐号

在项目中
git config --local user.name “你的名字”
git config --local user.email “你的邮箱”
或在全局中
git config --global user.name “你的名字”
git config --global user.email “你的邮箱”

在config文件中查看

2. 拷贝pub内容到github上

github配置ssh 访问

#3. 测试
ssh -T [email protected]