# 安装git
sudo apt-get install git
# 安装openssh服务器
# 如不成功,可参考:
http://blog.csdn.net/feliciafay/article/details/6561414
sudo apt-get install openssh-server
sudo do-release-upgrade
# 下面命令可测试是否安装成功:
ssh localhost # 远程登入
exit # 登出
cd ~/.ssh
ls # 没有找到ssh的公钥、密钥文件: id_rsa id_rsa.pub
# 用下面命令生成 公钥、密钥文件
ssh-keygen # 一般连续回车就行了,也可能要输入y,详情见:
http://doc.linuxpk.com/4240.html
# 将公钥内容拷入临时文件key.txt,待会儿要用
# cat id_rsa.pub > ~/key.txt
# 进入:
https://github.com/,注册免费帐户:
# Signup and Pricing -> create a free account
# 创建新仓库,命名为: HelloWorld,现在里面没文件
# Create a New Repo: Repository name: HelloWorld
# 将key.txt内容拷入: Key
# Account Settings -> SSH Keys -> Add SSH Key -> Add Key
# 经过实践得知:一个用户(主机),只能同时用一个账户
# 因为相同的公钥不能填入到不同的账户的SSH Keys中
# 于是,我们只能反复生成公钥、密钥来切换帐户
# 进入HelloWorld仓库
# Code -> Quick setup -> SSH
# 复制远程仓库地址: git@github.com:yanrk/HelloWorld.git
cd ~
mkdir Git
cd Git
# 将远程仓库拷入本机当前目录
git clone git@github.com:yanrk/HelloWorld.git
# 如果上面git命令出现如下错误:
# Agent admitted failure to sign using the key.
# Permission denied (publickey).
# fatal: The remote end hung up unexpectedly
# 可以用下面命令解决:
# ssh-add ~/.ssh/id_rsa
# 下面继续
ls # 可以发现在Git中多了一个新文件夹: HelloWorld
# 进入HelloWorld中
cd HelloWorld
# 新建一个HelloWorld.cpp文件
cat > HelloWorld.cpp
#include <iostream>
int main(int argc, char * argv[])
{
std::cout << "Hello World" << std::endl;
return(0);
}
^Z # (CTRL+Z)