在GitHub中生成个人访问令牌后,是否有必要将其存储在机器本地的某个地方?

如果是,是否有首选的存储方式?


当前回答

或者,您可以在主目录中创建一个~/.netrc文件,并将登录凭据保存在其中。

cat ~/.netrc
machine github.com login <login-id> password <token-password>

其他回答

为了在缓存中存储您的凭据并避免每次执行git操作时都登录,请遵循以下步骤:

导航到本地存储库文件夹。 在当前文件夹的终端:git config——global——replace-all credential。辅助缓存 执行git push或git pull。 使用用户名和访问令牌登录(访问令牌是您的密码)。令牌可以在GitHub中设置,并可以访问repo,工作流,write:packages和delete:packages。 重复git push或任何git操作,你会发现从现在开始它不再要求登录凭据。

你可以使用pass存储github https令牌。

将git主机映射到pass条目的两个备选方案:

Bash脚本映射到右传递项:

#!/usr/bin/env bash
# assuming "get" action from git and a config like this
# git config --global credential.helper $XDG_BIN_HOME'/git_credentials_from_pass $@'
while IFS= read -r line
do
  echo "$line"
  if [[ "$line" =~ host=.*github.com.* ]]; then
      echo "username=your_user_name"
      echo "password=$(pass show token_github.com/your_username)"
  #else ...
  fi
done

改变your_username和token_github.com的方式,你设置它通过pass插入。

这将添加令牌传递,无需输入或粘贴两次:

echo your_github_token | sed p | pass add token_github.com/your_username

安装pass-git-helper:

git config --global credential.helper '!pass-git-helper $@'

pass-git-helper需要一个ini文件来映射git请求和pass条目。 $ {XDG_CONFIG_HOME} / pass-git-helper git-pass-mapping.ini例子:

[DEFAULT]
username_extractor=entry_name
[github.com*]
target=token_${host}/your_github_username

尝试启用此功能以帮助跨推/拉持久化

git config credential.helper store

对于正在克隆的repo / macOS用户/安装iTerm2 https://iterm2.com/

使直到

只要在需要时单击该片段即可。 另外,你在用哦,我的zsh,对吧? https://github.com/ohmyzsh/ohmyzsh

curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg | sudo dd of=/usr/share/keyrings/githubcli-archive-keyring.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/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
gh auth login

它将要求输入协议和令牌

然后我再次克隆回购。它不是要信物

或者,您可以在主目录中创建一个~/.netrc文件,并将登录凭据保存在其中。

cat ~/.netrc
machine github.com login <login-id> password <token-password>