关于Git和GitHub权限(SSH和HTTPS,单个帐户和多个帐户)

When the local computer communicates with GitHub, the transmission is mainly based on two protocols, HTTPS and SSH, and the corresponding repository addresses are HTTPS URLs and SSH URLs.

当本地计算机与GitHub通信时,传输主要基于HTTPS和SSH这两个协议,并且相应的存储库地址为HTTPS URL和SSH URL。

The first thing to emphasize is that HTTPS URLs and SSH URLs correspond to two completely independent permission verification methods. The main difference is that HTTPS URLs use account passwords for verification, and SSH URLs use SSH key pairs for verification. In normal use, we can choose one according to the actual situation.

首先要强调的是,HTTPS URL和SSH URL与两种完全独立的权限验证方法相对应。 主要区别在于HTTPS URL使用帐户密码进行验证,而SSH URL使用SSH密钥对进行验证。 在正常使用中,我们可以根据实际情况选择一种。

HTTPS网址 (HTTPS URLs)

GitHub officially recommends the use of HTTPS URLs, because this method is more applicable (even in the case of a firewall or proxy), and is more convenient to use (easier configuration).

GitHub正式建议使用HTTPS URL,因为此方法更适用(即使在防火墙或代理的情况下),并且使用更方便(更容易配置)。

When using the HTTPS URLs address clone /fetch/pull/push repository, there is no need to configure the local system in advance, just enter the GitHub account and password. However, if you have to manually enter the account password every time, it is also a very tedious thing.

使用HTTPS URL地址克隆/ fetch / pull / push存储库时,无需预先配置本地系统,只需输入GitHub帐户和密码。 但是,如果您每次必须手动输入帐户密码,这也是一件非常繁琐的事情。

Fortunately, there are already multiple mechanisms to make operations less troublesome.

幸运的是,已经有多种机制可以减少操作的麻烦。

In the macOS, when the Keychain mechanism is enabled, after entering the GitHub account password for the first time, the authentication information will be automatically saved in the Keychain.app of the system, and the authentication information saved in the Keychain.app will be automatically read the next time the repository is accessed again.

在macOS中,启用钥匙串机制后,首次输入GitHub帐户密码后,身份验证信息将自动保存在系统的Keychain.app中,而保存在Keychain.app中的身份验证信息将为下次再次访问该存储库时将自动读取。

On other systems, although there is no Keychain mechanism, Git provides a credential helper mechanism, which can cache the account password in memory for a period of time (default 15 minutes), or store it as a file (such as ~/. git-credentials). Of course, if the macOS does not enable the Keychain mechanism, this method can also be used.

在其他系统上,尽管没有Keychain机制 ,但Git提供了凭据帮助程序机制,该机制可以将帐户密码在内存中缓存一段时间(默认为15分钟),或将其存储为文件(例如〜/。git)。 -credentials )。 当然,如果macOS没有启用钥匙串机制,则也可以使用此方法。

# cache credential in memory
$ git config --global credential.helper cache# store credential in ~/.git-credential
$ git config --global credential.helper store

When credential.helper is set to store, after entering the GitHub account password for the first time, it will be automatically saved to the such as ~/.git-credentials file in the form of https://user:pass@github.com ; next time When accessing the repository, the authentication information saved in ~/.git-credentials will be automatically read.

credential.helper设置为存储时,首次输入GitHub帐户密码后,它将以https:// user:pass @ github的形式自动保存到诸如〜/ .git-credentials文件中。 com ; 下次访问存储库时,将自动读取保存在〜/ .git-credentials中的身份验证信息。

Or you can use the token mechanism. In the Developer Settings of the Github user’s Settings, you can create and manage tokens in the Personal access tokens column, as long as the token id is saved locally. Then in a repository, in the config file, just change the format of the remote url part to https://your_token_id@github.com/your_repo_name.git (note: later, when more remote repo interactions such as git clone, the URL must bring the token id) .

或者,您可以使用令牌机制。 在Github用户设置的开发人员设置中,您可以在“个人访问令牌”列中创建和管理令牌,只要令牌ID在本地保存即可。 然后在存储库中的配置文件中,只需将远程URL部分的格式更改为https://your_token_id@github.com/your_repo_name.git ( 注意 稍后,当更多远程回购交互(例如git clone)时 ,URL必须带有令牌ID

Another situation that needs to be explained is that if 2FA (two-factor authentication) is enabled in GitHub, when entering the GitHub account password in the local system, you cannot enter the original password (that is, the login password of the GitHub website), but need to Create a Personal access token in the GitHub website in advance, and then use the access token as a password to enter when accessing the code repository needs to be verified.

需要说明的另一种情况是,如果在GitHub中启用了2FA(双重身份验证),则在本地系统中输入GitHub帐户密码时,您将无法输入原始密码(即GitHub网站的登录密码) ),但需要创建一个个人 预先在GitHub网站中访问令牌 ,然后在需要验证访问代码存储库时使用访问令牌作为密码输入。

SSH URL (SSH URLs)

In addition to HTTPS URLs, you ca

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值