操作环境

  • ubuntu 16.04 终端输入: lsb_release -a
1
2
3
4
5
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 16.04 LTS
Release: 16.04
Codename: xenial
  • git 和 ssh

具体操作

github一般支持http和ssh两种传输协议(可能还有其他的,作为菜鸟暂时不作研究),而使用clone的时候,可以选择两者之一,生成地址,直接选用http的话,
不需要输入密码和验证,如果采用ssh则需要将上传到github上面的公钥和本地的私钥进行匹配,验证成功后才能进行相关一系列的操作。

  • 安装git 和 ssh sudo apt-get install git ssh

  • 为了和Github的远程仓库进行传输,需要进行SSH加密设置。

1
2
3
ssh-keygen -t rsa -C "{[email protected]}" // 用你的邮箱替换{[email protected]}
可以不输入其他信息,一直敲回车直到命令完成。
这时你的用户目录下会出现名为.ssh 的文件夹(默认隐藏),点进去能看到 id_rsa 和 id_rsa.pub 两个文件,其中 id_rsa 是私钥,不能让怪人拿走, id_rsa.pub 是公钥,无需保密
  • 登录Github,点击右上角头像下的Settings -> SSH and GPG keys -> New SSH key ,在title中输入名称,Key中输入公钥(id_rsa.pub中的所有内容)

  • 终端下面设置git

1
2
git config --global user.name "{name}" // 用你的名字代替{name}
git config --global user.email "{[email protected]}" // 用你的邮箱替换{[email protected]}
  • 打开你需要下载目录,使用ssh协议远程下载你的项目
1
2
cd Documents
git clone [email protected]:xxx/yyy.git

参考链接:
http://playingfingers.com/2016/03/26/build-a-blog/#ssh
http://www.yiibai.com/git/git_environment.html