linux 安装配置git

1. 安装git

yum install git
Last metadata expiration check: 0:08:02 ago on Wed 29 Jun 2022 02:43:07 PM CST.
Dependencies resolved.
======================================================================================================================== Package                         Architecture          Version                           Repository                Size
========================================================================================================================Installing:
 git                             x86_64                2.27.0-1.el8                      AppStream                164 k
Installing dependencies:
 git-core                        x86_64                2.27.0-1.el8                      AppStream                5.7 M
 git-core-doc                    noarch                2.27.0-1.el8                      AppStream                2.5 M
 perl-Error                      noarch                1:0.17025-2.el8                   AppStream                 46 k
 perl-Git                        noarch                2.27.0-1.el8                      AppStream                 77 k
 perl-TermReadKey                x86_64                2.37-7.el8                        AppStream                 40 k

Transaction Summary
========================================================================================================================Install  6 Packages

Total download size: 8.5 M
Installed size: 45 M
Is this ok [y/N]: y
Downloading Packages:
(1/6): git-2.27.0-1.el8.x86_64.rpm                                                      335 kB/s | 164 kB     00:00
(2/6): perl-Error-0.17025-2.el8.noarch.rpm                                              291 kB/s |  46 kB     00:00
(3/6): perl-Git-2.27.0-1.el8.noarch.rpm                                                  42 kB/s |  77 kB     00:01
(4/6): perl-TermReadKey-2.37-7.el8.x86_64.rpm                                           274 kB/s |  40 kB     00:00
(5/6): git-core-doc-2.27.0-1.el8.noarch.rpm                                             430 kB/s | 2.5 MB     00:05
(6/6): git-core-2.27.0-1.el8.x86_64.rpm                                                 429 kB/s | 5.7 MB     00:13
------------------------------------------------------------------------------------------------------------------------Total                                                                                   644 kB/s | 8.5 MB     00:13
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                                                                1/1
  Installing       : git-core-2.27.0-1.el8.x86_64                                                                   1/6
  Installing       : git-core-doc-2.27.0-1.el8.noarch                                                               2/6
  Installing       : perl-TermReadKey-2.37-7.el8.x86_64                                                             3/6
  Installing       : perl-Error-1:0.17025-2.el8.noarch                                                              4/6
  Installing       : perl-Git-2.27.0-1.el8.noarch                                                                   5/6
  Installing       : git-2.27.0-1.el8.x86_64                                                                        6/6
  Running scriptlet: git-2.27.0-1.el8.x86_64                                                                        6/6
  Verifying        : git-2.27.0-1.el8.x86_64                                                                        1/6
  Verifying        : git-core-2.27.0-1.el8.x86_64                                                                   2/6
  Verifying        : git-core-doc-2.27.0-1.el8.noarch                                                               3/6
  Verifying        : perl-Error-1:0.17025-2.el8.noarch                                                              4/6
  Verifying        : perl-Git-2.27.0-1.el8.noarch                                                                   5/6
  Verifying        : perl-TermReadKey-2.37-7.el8.x86_64                                                             6/6

Installed:
  git-2.27.0-1.el8.x86_64                  git-core-2.27.0-1.el8.x86_64        git-core-doc-2.27.0-1.el8.noarch
  perl-Error-1:0.17025-2.el8.noarch        perl-Git-2.27.0-1.el8.noarch        perl-TermReadKey-2.37-7.el8.x86_64

Complete!

2. 配置用户名和邮箱

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

这里global是配置全局用户名和邮箱,去掉–global参数,可以为当前目录的仓库单独配置用户名和邮箱。

完了可以使用下面的命令查看配置

 git config --get user.name

3. 配置SSH

  • 3.1 生成SSH密钥

    $ ssh-keygen -t ed25519 -C "[email protected]"
    

    这将使用提供的电子邮件作为标签创建一个新的 SSH 密钥。

    ed25519是一种密码算法。

    Generating public/private rsa key pair.
    Enter file in which to save the key (/root/.ssh/id_rsa): github
    Enter passphrase (empty for no passphrase):
    Enter same passphrase again:
    Your identification has been saved in github.
    Your public key has been saved in github.pub.
    The key fingerprint is:
    SHA256:sxxxxxxxxxxxxxxxxxxxxxxx xxx@xxx
    The key's randomart image is:
    +---[RSA 3072]----+
    |        ....o ..=|
    |         ..+ = B+|
    |      o .   = X *|
    |       +   o = * |
    |      . S +   . .|
    |     . + + o     |
    |      . + o o... |
    |         B . .o.E|
    |        +.+. o+*+|
    +----[SHA256]-----+
    

    运行后依次需要输入密钥文件名、密钥密码和确认密码。可以直接enter,使用默认的。
    我这边是给出了文件名.

  • 3.2 将SSH密钥添加到ssh-agent

    eval "$(ssh-agent -s)"
    $ ssh-add ~/.ssh/github
    
    Identity added: /root/.ssh/github ([email protected])
    

    将github替换为你的密钥名。

    如果不进行这一步,直接跳到下面第三步,将不能使用ssh访问github。

    ssh -T [email protected]
    The authenticity of host 'github.com (20.205.243.166)' can't be established.
    ECDSA key fingerprint is SHA256:pxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.
    Are you sure you want to continue connecting (yes/no/[fingerprint])? Y
    Please type 'yes', 'no' or the fingerprint: yes
    Warning: Permanently added 'github.com,20.205.243.166' (ECDSA) to the list of known hosts.
    [email protected]: Permission denied (publickey).
    

    访问被拒绝。

  • 3.3 复制公钥,打开 github - setting - 左侧 SSH and GPG keys - new SSH key

    测试访问

    ssh -T [email protected]
    Hi xxxx! You've successfully authenticated, but GitHub does not provide shell access.
    

4. 使用SSL方式克隆仓库到本地

 git clone [email protected]:user/repo.git
Cloning into 'repo'...
remote: Enumerating objects: 55, done.
remote: Counting objects: 100% (55/55), done.
remote: Compressing objects: 100% (39/39), done.
remote: Total 55 (delta 21), reused 47 (delta 13), pack-reused 0
Receiving objects: 100% (55/55), 53.29 KiB | 230.00 KiB/s, done.
Resolving deltas: 100% (21/21), done.

文章参考:

github文档 - 在 Git 中设置用户名
github文档 - 生成新的 SSH 密钥

猜你喜欢

转载自blog.csdn.net/u012413551/article/details/125524039