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]-----+
    

    実行後、キーファイル名、キーパスワード、確認パスワードを順に入力する必要があります。デフォルトを直接入力して使用できます。
    ここでファイル名を指定します。

  • 3.2 ssh-agent に SSH キーを追加する

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

    github をキー名に置き換えます。

    この手順を実行しない場合は、次の 3 番目の手順に直接スキップしてください。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を開きます-設定- 左のSSH および GPG キー-新しい SSH キー

    テスト アクセス

    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 docs - Git でのユーザー名の設定
github docs - 新しい SSH キーの生成

おすすめ

転載: blog.csdn.net/u012413551/article/details/125524039