ubuntu16.04下github的安装和使用

一.检查是否安装了git

sulei@sulei:~$ git version
git version 2.7.4

二.如果没有安装,则使用如下的命令

sudo apt-get install git git-core

三:进行SSH认证

sulei@sulei:~$ ssh -T git@github.com
Warning: Permanently added the RSA host key for IP address '192.30.255.113' to the list of known hosts.
Permission denied (publickey).

验证失败
四.配置信息

$ git config --global user.name "Your Name"
$ git config --global user.email "[email protected]"
sulei@sulei:~/.ssh$ git config --list
user.name=shursulei
use.email=1368455669@qq.com

五.
配置完成后,需要创建验证用的公钥,因为git是通过ssh的方式访问资源库的,所以需要在本地创建验证用的文件。使用命令ssh-keygen -C ‘you email [email protected]’ -t rsa(注意ssh与-keygen之间没有空格),会在用户目录~/.ssh/下建立相应的密钥文件。
创建完公钥后,需要上传。使用命令cd ~/.ssh进入~/.ssh文件夹,输入gedit id_rsa.pub打开id_rsa.pub文件,复制其中所有内容。

sulei@sulei:~$ ssh-keygen -C "[email protected]" -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/sulei/.ssh/id_rsa): 
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /home/sulei/.ssh/id_rsa.
Your public key has been saved in /home/sulei/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:Xy/z8xHEY4xiNynbfM67SpjWKot/gP2AzpIxAyR9TFI 1368455669@qq.com
The key's randomart image is:
+---[RSA 2048]----+
|  ..+E           |
| . o.o        =  |
|  o .      + = * |
|   .      . B + .|
|    .   S  ..o o |
|     + o = .+.+ .|
|      B   =+oo.+ |
|     o o...oo+. o|
|      ...o+. .o=o|
+----[SHA256]-----+

再你注册的邮箱中将复制的内容写进去.
六.再次链接

sulei@sulei:~/.ssh$ ssh -T git@github.com
Hi shursulei! You've successfully authenticated, but GitHub does not provide shell access.

七.创建版本库并初始化

sulei@sulei:~$ mkdir learngit
sulei@sulei:~$ cd learngit/
sulei@sulei:~/learngit$ pwd
/home/sulei/learngit
sulei@sulei:~/learngit$ git init
初始化空的 Git 仓库于 /home/sulei/learngit/.git/

言归正传,现在我们编写一个readme.txt文件,内容如下:

sulei@sulei:~/learngit$ gedit readme.txt
内
Git is a version control system.
Git is free software.

提交.但是出错

sulei@sulei:~/learngit$ git add readme.txt 
sulei@sulei:~/learngit$ git commit -m "wrote a readme file"

*** Please tell me who you are.

Run

  git config --global user.email "[email protected]"
  git config --global user.name "Your Name"

to set your account's default identity.
Omit --global to set the identity only in this repository.

fatal: unable to auto-detect email address (got 'sulei@sulei.(none)')
sulei@sulei:~/learngit$ git config --global user.name "shursulei"
sulei@sulei:~/learngit$ git config --global user.email "[email protected]"
修改后如上:
sulei@sulei:~/learngit$ git commit -m "wrote a readme file"
[master (根提交) cf8d9c1] wrote a readme file
 1 file changed, 2 insertions(+)
 create mode 100644 readme.txt

参考地方:

http://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000/0013743858312764dca7ad6d0754f76aa562e3789478044000

你可能感兴趣的:(ubuntu)