1. 首先确保安装了git:
git --version
2. 如果没有安装,使用下述命令进行安装,若安装了则跳过2:
yum install git
3. 配置git:
# 配置,邮箱填写你的github注册邮箱
git config --global user.name “your name”
git config --global user.email "your_email@example.com"
# 检查配置
git config --list
4. 进入目录~/.ssh下,执行下面脚本一路Enter生成ssh密钥和公钥:
cd ~/.ssh
# 邮箱填写你的github注册邮箱
ssh-keygen -t ecdsa -b 521 -C "your_email@example.com"
此时该目录下生成两个文件:id_ecdsa和id_ecdsa.pub,打开id_ecdsa.pub,复制内容,
cd ~/.ssh
vi id_ecdsa.pub
# 内容类似下面
ecdsa-sha2-nistp521 AAAAE2VjZHNhLXN********1MjEAAAAIbmlzdHA1MjEAAACFBAAptVsQ1Pfj1XfaCRmbHZNI+xfr/L1QXvrBwvGEjYIvmlfjns0YAYGy7GCRlshctz3peRbW1ID4OS7YSKB+516W/ABztfJiHGHfkWxqtr8HBymUXC4epbKC4PaLsNhTLM690Q3ftRuFv1cFssYXPXuIIVFtA1z8J4IA0axNO/uUB4pHgg== your_email@example.com
5. 打开github登陆,找到如下位置:
顺序:
? ? ? ? 5.1.点头像找settings;
? ? ? ? 5.2.左侧菜单栏找到 SSH and GPG keys;
? ? ? ? 5.3.点击右上角New SSH key粘贴刚才复制的公钥内容,命名随意哈。
6. 输入以下脚本测试key,,看能否登陆github.
ssh -T git@github.com
7. 看到下面提示,输入yes即可;
The authenticity of host 'github.com (207.97.227.239)' can't be established.
RSA key fingerprint is 16:27:ac:a5:76:28:2d:36:63:1b:56:4d:eb:df:a6:48.
Are you sure you want to continue connecting (yes/no)?
8. 成功后回显示
Hi xxxxx! You've successfully authenticated, but GitHub does not
provide shell access.
注意:这里通过ssh配置,因此git配置远程仓库使用ssh型的:
# 基本操作
# 初始化git
git init
# 本地添加暂存
git add .
# 提交到本地仓库
git commit -m 'first commit'
# 添加远程仓库
git remote add origin git@github.com:yourname/xxxxx.git
# 提交到远程github仓库
git push origin branch_name
|