https://github.com/cli/cli/blob/trunk/docs/install_linux.md
ssh登录。检查密钥是否存在:
ssh -T [[email protected]](<mailto:[email protected]>)
不存在则生成SSH密钥并添加到Github https://github.com/settings/keys
gitconfig 4 codeup
Host codeup.aliyun.com
HostName codeup.aliyun.com
IdentityFile ~/.ssh/higgs
PreferredAuthentications publickey
IdentityAgent none
IdentitiesOnly yes
添加到ssh-agent统一 托管 | https://docs.github.com/en/authentication/connecting-to-github-with-ssh/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent#adding-your-ssh-key-to-the-ssh-agent
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_ed25519
ssh-add -l
# 启动 ssh-agent(如果未运行)
if [ -z "$SSH_AUTH_SOCK" ]; then
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_ed25519 # 自动添加常用密钥
fi
添加到GIhub账号
<aside> <img src="notion://custom_emoji/9040cc52-5c24-4c85-8328-7061a24dd7f9/1b5d969b-881f-80ef-a689-007a939b2a43" alt="notion://custom_emoji/9040cc52-5c24-4c85-8328-7061a24dd7f9/1b5d969b-881f-80ef-a689-007a939b2a43" width="40px" />
gh也可以用于直接将公钥导入Github账号
gh auth login
</aside>
检验
https://docs.github.com/zh/authentication/connecting-to-github-with-ssh/testing-your-ssh-connection
https://docs.github.com/zh/authentication/connecting-to-github-with-ssh/testing-your-ssh-connection
正常情况:[ssh -T [email protected]](https://hazysite.notion.site/ssh-T-git-github-com-1b5d969b881f80829991e88422a56404)
调试:
ssh-agent bash
ssh -vT [email protected]
Git配置
可以选用Github CLI 命令自动配置https://cli.github.com/manual/
(type -p wget >/dev/null || (sudo apt update && sudo apt-get install wget -y)) \\
&& sudo mkdir -p -m 755 /etc/apt/keyrings \\
&& out=$(mktemp) && wget -nv -O$out <https://cli.github.com/packages/githubcli-archive-keyring.gpg> \\
&& cat $out | sudo tee /etc/apt/keyrings/githubcli-archive-keyring.gpg > /dev/null \\
&& sudo chmod go+r /etc/apt/keyrings/githubcli-archive-keyring.gpg \\
&& echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/githubcli-archive-keyring.gpg] <https://cli.github.com/packages> stable main" | sudo tee /etc/apt/sources.list.d/github-cli.list > /dev/null \\
&& sudo apt update \\
&& sudo apt install gh -y
sudo apt update
sudo apt install gh
gh auth setup-git
<aside> <img src="notion://custom_emoji/9040cc52-5c24-4c85-8328-7061a24dd7f9/1b5d969b-881f-804c-bfba-007a5862d1d7" alt="notion://custom_emoji/9040cc52-5c24-4c85-8328-7061a24dd7f9/1b5d969b-881f-804c-bfba-007a5862d1d7" width="40px" />
Git 的全局配置文件在~/.gitconfig ;
Git 的项目配置文件在 /.git/config ;
</aside>
生成的结果可以参考
# This is Git's per-user configuration file.
[user]
name = "leo2www"
email = "[email protected]"
[http]
proxy = socks5://127.0.0.1:20173
[https]
proxy = socks5://127.0.0.1:20173
[credential "<https://github.com>"]
helper =
helper = !/usr/bin/gh auth git-credential
[credential "<https://gist.github.com>"]
helper =
helper = !/usr/bin/gh auth git-credential
[core]
editor = \\"C:\\\\Software\\\\Microsoft VS Code\\\\bin\\\\code\\" --wait
autocrlf = true
# Git for Windows need \\\\ or /
sshCommand = ssh -F D:\\\\Open-SSH\\\\config
[credential "<https://github.com>"]
helper =
helper = !'C:\\\\Program Files\\\\GitHub CLI\\\\gh.exe' auth git-credential
[credential "<https://gist.github.com>"]
helper =
helper = !'C:\\\\Program Files\\\\GitHub CLI\\\\gh.exe' auth git-credential
[http "<https://github.com>"]
proxy = <http://hazy:[email protected]:10810>
[https "<https://github.com>"]
proxy = <http://hazy:[email protected]:10810>
[url "[email protected]:"]
insteadOf = <https://github.com/>
[user]
name = hazy_PS
email = [email protected]
signingkey = C:\\\\Users\\\\hazy\\\\.ssh\\\\id_ed25519.pub
[gpg]
format = ssh
[commit]
gpgsign = true
Verified commit
<aside> 💡
本地 commit 时配置 Git 自动加入 GitHub Setting中接受的 gpg(signing key产生的也行),
git config --global commit.gpgsign true.
</aside>
git config --global gpg.format ssh
git config --global user.signingkey /PATH/TO/.SSH/KEY.PUB
设置中增加 Signing keys
https://github.com/settings/keys
<aside>
verified commit 会直接显示 Github 账户,替代git提交输入的 user.name user.email
</aside>