多个开发人员如何“缓存”多个开发人员他们在远程计算机上的 Git 个人访问令牌?

发布于 2025-01-10 14:50:51 字数 738 浏览 0 评论 0原文

在我们的团队中,我们需要直接在共享的远程计算机上开发代码。我们在这台机器上有一个 GitHub 存储库,我们中的一个人有时需要通过 SSH 连接到远程计算机,以开发代码,也许还需要从 GitHub 存储库拉取/推送到该存储库。我们每个人都可以从 GitHub 生成自己的个人访问令牌 (PAT),以在进行 Git 操作时使用。

在我们自己的 PC 上,这相当不错,因为我们使用 Git Credential Manager (GCM) 来缓存凭据(这非常安全,因为需要使用 Windows 登录信息等)来访问信息)。

但随后在(Linux)远程计算机上,我们在 /home/user/repository 处有一个存储库的克隆,其原始远程设置为类似 https://github.com/团队/blahblahblah。然后,经过一番搜索后,我们找不到一种干净的方法来获取多个用户(多个用户名及其相应的 PAK)的 Git Credential Helper 存储凭据。我们最终每次都必须输入用户名和 PAK(是的,我们可以通过超时来缓存它,但这不是很有帮助)。

使用 GitHub SSH 远程,一种选择是每个人都可以在远程上拥有自己的安全、受密码保护的 SSH 密钥,因此每次人 A 想要执行 git 时,他们都必须提供密码来解锁 SSH 密钥。他们只需在 Git Config 上设置正确的作者姓名,以便读取正确的 SSH 密钥。

但我们正在寻找一种更清洁的方法来做到这一点。您知道这方面有什么特殊的工具或机制吗?

Within our team, we need to develop code directly on a shared remote machine. We have a GitHub repo on this machine, and from time to time one of us needs to SSH into the remote machine, to develop code, and perhaps pull from/push to the GitHub repo. Each of us can generate his/her own Personal Access Tokens (PAT) from GitHub, to use when doing Git operation.

On our own PCs this is pretty okay, as we use Git Credential Manager (GCM) to cache the credentials (and this is pretty much safe, since one needs to use, for instance, Windows Login information, to access the information).

But then on the (Linux) remote machine, we have a clone of the repo at /home/user/repository with its origin remote set to something like https://github.com/team/blahblahblah. Then after a bit of search we couldn't find a clean way to get the Git Credential Helper store credentials for multiple users (multiple usernames and their corresponding PAK). We end up having to enter username and PAK everytime (yes we can cache it with a timeout but that's not very helpful).

With GitHub SSH remote, one option was that everyone can have their own secure, password protected SSH key on the remote, so everytime person A wants to do git, they have to provide password to unlock the SSH key. They just need to set the correct author name on Git Config so that correct SSH key gets read.

But we are looking for a cleaner way to do this. Do you know any special tools or mechanism for this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

澜川若宁 2025-01-17 14:50:51

如果您使用 SSH 而不是 HTTP,因此使用私钥而不是访问令牌,则可以通过SSH 代理转发轻松实现这一点。

简而言之:

  • SSH 代理是一个在后台运行的程序,它将您的私钥保存在内存中,并通过本地“套接字”按需提供对它们的访问。
  • git 完全支持这种机制,并且 GitHub 根据提供的密钥识别用户(您始终使用用户名 "[email protected]")
  • 当与远程服务器建立 SSH 连接时,您可以要求“转发”您的本地代理(在命令行上使用 OpenSSH 的 -A 选项,或者在您使用的任何客户端中使用等效选项)。
  • 这允许远程服务器上的程序在套接字上请求私钥信息,该套接字请求通过SSH连接转发回您的PC。

由于转发的代理仅在用户登录时可用,并且私钥本身不需要复制到服务器,因此这应该可以满足您的需求。

If you use SSH rather than HTTP, and therefore private keys rather than access tokens, you can achieve this easily with SSH Agent Forwarding.

In a nutshell:

  • An SSH Agent is a program running in the background that holds your private keys in memory, and provides access to them on demand via a local "socket".
  • git fully supports this mechanism, and GitHub identifies the user based on the key offered (you always use the username "[email protected]")
  • When establishing an SSH connection to a remote server, you can ask to "forward" your local agent (with the -A option to OpenSSH on the command-line, or an equivalent option in whatever client you use).
  • This allows programs on the remote server to ask for private key information on a socket which forwards the request over the SSH connection back to your PC.

Since the forwarded agent is only usable while the user is logged in, and the private key itself doesn't need to be copied to the server, this should meet your needs.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文