Ubuntu上Git的安装与配置

安装

git的安装很简单

sudo apt-get install git

配置身份标识

配置用户名和邮箱

git config --global user.email "you@example.com"
git config --global user.name "Your Name"

如果仅在本仓库设置身份标识,则省略 —global 参数。

配置ssh公钥

首先查看系统是否有id_rsa.pub

cat ~/.ssh/id_rsa.pub

如果没有的话则用ssh-keygen创建

ssh-keygen -C 'your@email.com' -t rsa

然后会在~/.ssh/下生成相应的密钥文件:

Generating public/private rsa key pair.
Enter file in which to save the key (/home/zyx/.ssh/id_rsa): 
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /home/zyx/.ssh/id_rsa.
Your public key has been saved in /home/zyx/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:lSNdrKU2FSnncGEcuUzMHfXqxxOsxFoX2NA/TDf17Es 1162178485@qq.com
The key's randomart image is:
+---[RSA 2048]----+
|           =*Ooo+|
|         .o+& ==+|
|        . =& oooB|
|          o=.= .o|
|        S. . +.Eo|
|            +.+.o|
|           . ..oo|
|               ..|
|                 |
+----[SHA256]-----+

然后上传公钥到github。首先复制~/.ssh/id_rsa.pub文件中的内容,然后进入Github,在settings->SSH and GPG keys,点击New SSH key,在Title处填写任意内容,在key内填写复制的id_rsa.pub文件中的内容。

解决一些问题

警告:Warning: Permanently added the RSA host key for IP address ‘192.30.255.112’ to the list of known hosts.

修改/etc/hosts/文件

sudo vim /etc/hosts

添加一行:

192.30.255.112 github.com