在GitHub中生成个人访问令牌后,是否有必要将其存储在机器本地的某个地方?
如果是,是否有首选的存储方式?
在GitHub中生成个人访问令牌后,是否有必要将其存储在机器本地的某个地方?
如果是,是否有首选的存储方式?
当前回答
或者,您可以在主目录中创建一个~/.netrc文件,并将登录凭据保存在其中。
cat ~/.netrc
machine github.com login <login-id> password <token-password>
其他回答
使用git代替。基本上,将每个https://github调用替换为访问令牌+ https://
git config——global url."https://<username>:<github-token>@github.com/". insteadof "https://github.com/
现在每次调用github都会自动添加您的凭据。
我在这里找到了很好的答案。 更多关于git insteadOf的信息。
或者,您可以在主目录中创建一个~/.netrc文件,并将登录凭据保存在其中。
cat ~/.netrc
machine github.com login <login-id> password <token-password>
以我为例,在Ubuntu中,被接受的解决方案不能处理像这样的消息
Git: 'credential-manager'不是Git命令
但是店长却做得很好:
git config --global credential.helper store
在我的用例中,我将PAT存储在密码管理器中,例如LastPass, KeePass, 1Password。当我在Linux环境(例如Docker)中需要它时,我将PAT保存在一个环境变量中,然后使用git的凭据帮助器设置。例如:
git config --global credential.helper 'cache --timeout 600'
<< eof tr -d ' ' | git credential-cache store
protocol=https
host=github.com
username=nonce
password=${GITHUB_PAT}
eof
对于PAT,用户名可以是任何东西,除了空白。以下是详细阐述的要点:
https://gist.github.com/rwcitek/da862e9e27cc28d3e96e62a2ca4b2b64
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
它将要求输入协议和令牌
然后我再次克隆回购。它不是要信物