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 Mgit-core-doc noarch 2.27.0-1.el8 AppStream 2.5 Mperl-Error noarch 1:0.17025-2.el8 AppStream 46 kperl-Git noarch 2.27.0-1.el8 AppStream 77 kperl-TermReadKey x86_64 2.37-7.el8 AppStream 40 kTransaction Summary
========================================================================================================================Install 6 PackagesTotal 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 transactionPreparing : 1/1Installing : git-core-2.27.0-1.el8.x86_64 1/6Installing : git-core-doc-2.27.0-1.el8.noarch 2/6Installing : perl-TermReadKey-2.37-7.el8.x86_64 3/6Installing : perl-Error-1:0.17025-2.el8.noarch 4/6Installing : perl-Git-2.27.0-1.el8.noarch 5/6Installing : git-2.27.0-1.el8.x86_64 6/6Running scriptlet: git-2.27.0-1.el8.x86_64 6/6Verifying : git-2.27.0-1.el8.x86_64 1/6Verifying : git-core-2.27.0-1.el8.x86_64 2/6Verifying : git-core-doc-2.27.0-1.el8.noarch 3/6Verifying : perl-Error-1:0.17025-2.el8.noarch 4/6Verifying : perl-Git-2.27.0-1.el8.noarch 5/6Verifying : perl-TermReadKey-2.37-7.el8.x86_64 6/6Installed: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.noarchperl-Error-1:0.17025-2.el8.noarch perl-Git-2.27.0-1.el8.noarch perl-TermReadKey-2.37-7.el8.x86_64Complete!
2. 配置用户名和邮箱
git config --global user.name "username"
git config --global user.email "your_email@example"
这里global是配置全局用户名和邮箱,去掉–global参数,可以为当前目录的仓库单独配置用户名和邮箱。
完了可以使用下面的命令查看配置
git config --get user.name
3. 配置SSH
-
3.1 生成SSH密钥
$ ssh-keygen -t ed25519 -C "your_email@example"
这将使用提供的电子邮件作为标签创建一个新的 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 (xxxxx@xxx)
将github替换为你的密钥名。
如果不进行这一步,直接跳到下面第三步,将不能使用ssh访问github。
ssh -T git@github The authenticity of host 'github (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,20.205.243.166' (ECDSA) to the list of known hosts. git@github: Permission denied (publickey).
访问被拒绝。
-
3.3 复制公钥,打开 github - setting - 左侧 SSH and GPG keys - new SSH key
测试访问
ssh -T git@github Hi xxxx! You've successfully authenticated, but GitHub does not provide shell access.
4. 使用SSL方式克隆仓库到本地
git clone git@github: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 密钥
发布评论