github 使用 personal access token 认证

最近又因为这件事情折腾半小时, 索性记录下来.

  1. 因为公司电脑有防火墙或者公司电脑访问策略的问题, 不能使用 git 协议访问 github.com 的 push/pull, 所以只能使用 https 协议, 比如: https://github.com/int0x03/samples.git
  2. github.com 已经禁止使用账户加密码来操作 git push/pull, 看这里: https://docs.github.com/en/get-started/git-basics/about-remote-repositories#cloning-with-https-urls
  3. 如果使用用户名 + 密码会出现下面的错误:

    git push origin master
    Username for 'https://github.com': int0x03
    Password for 'https://int0x03@github.com':
    remote: Support for password authentication was removed on August 13, 2021.
    remote: Please see https://docs.github.com/get-started/getting-started-with-git/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication.
    fatal: Authentication failed for 'https://github.com/int0x03/samples.git/'
  4. 所以要先添加 personal access token 然后把 token 做密码来访问. 具体路径是: github.com 右上角点头像, 进入 Settints -> Developer setttings -> Personal access tokens -> token classic 添加.
  5. 添加完成, 选择生产 token, 这个token 可以设置终止日期的.
  6. 可选把 token 放到 iTerm 的password 里面.

标签: none

添加新评论