https://www.cnblogs.com/woider/p/6533709.html
1.安装git
apt-get install git
2.配置 Git 用户信息
把用户名和邮箱换成你自己的,键入命令后屏幕没有输出,则表示设置成功了
git config --global user.name "woider"
git config --global user.email "woider@gmail.com"
3.开启SSH服务
apt-get install ssh //开启
ps -e | grep sshd //查看状态
4. 使用 ls -al ~/.ssh 命令查看 ssh key 是否存在,若存在则忽略这一步
生成 SSH KEY: ssh-keygen -t rsa -C "woider@gmail.com"
↑ 生成 ssh key 过程中,会让你填写 passphrase,连按三次回车跳过即可
5.查看ssh key
id_rsa 为私钥,id_rsa.pub 为公钥
root@localhost:~# cd /root/.ssh
root@localhost:~/.ssh# ls -a
6.打开 id_rsa.pub 文件,将内容复制到剪贴板:
vim id_rsa.pub
7.添加sshk
登录 GitHub,打开 Personal settings 页面,选择 SSH and GPG keys 选项:
粘贴刚复制的公匙
添加 SSH key 之后,Linux 就可以通过 SSH 建立本地 Git 与 GitHub 的连接了。
8.克隆仓库到本地
通过 SSH 地址将 GitHub 仓库克隆到本地:
git clone git@github.com:woider/baidu.git
克隆到本地的仓库会自动关联远程仓库,可以通过 git remote -v 命令查看关联状态
注意:如果克隆的是其他人的仓库,由于没有权限,你将不能推送修改。
/* 创建一个 readme.md 文件 */
root@localhost:/home/baidu# vim readme.md /* 输出 readme.md 文件内容 */
root@localhost:/home/baidu# cat readme.md
Git关联GitHub
============= /* 将文件添加到暂存区 */
root@localhost:/home/baidu# git add readme.md /* 提交本次修改 */
root@localhost:/home/baidu# git commit -m "add readme file"
[master 228d321] add readme file
file changed, insertions(+)
create mode readme.md /* 推送到远程仓库 */
root@localhost:/home/baidu# git push origin master
Counting objects: , done.
Compressing objects: % (/), done.
Writing objects: % (/), bytes | bytes/s, done.
Total (delta ), reused (delta )
To git@github.com:woider/baidu.git
36c5c1c..228d321 master -> master root@localhost:/home/baidu#
我的git
echo“#linux_configurations”>> README.md
git init
git add README.md
git commit -m“first commit”
git remote add origin git@github.com:feilongjiang / linux_configurations.git
git push -u origin master