我是在本地电脑上修改、开发应用代码,然后想推送到GitHub私有仓库,并在服务器上直接克隆、编辑、更新对应的项目。
现在GitHub搞2FA认证了,我是直接用谷歌浏览器存的Passkey。这块我就不介绍了。总之本文就只讲personal access token的事:
我执行git clone命令后,会提示让我输入GitHub账号密码。以前是可以直接输入账号密码的,但是现在我输入账密后它还是显示克隆失败,并显示:
(2024年12月的效果:)
Cloning into 'folder_name'...
Username for 'https://github.com': user_name
Password for 'https://user_name@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/user_name/folder_name.git/'
(2026年8月的效果:)
remote: Invalid username or token. Password authentication is not supported for Git operations.
fatal: Authentication failed for 'https://github.com/user_name/folder_name.git/'
也就是说现在不支持仅用账号密码来克隆GitHub项目了,解决方案是在输入密码时改为输入personal access token。获取personal access token的方式:
- 进入github.com/settings/pe…
现在personal access token分成fine-grained和classic两种。
效果差不多,我就只介绍fine-grained token了。 - 创建token:
- 指定token名称(会在token列表中看到,方便明确哪个token是拿来干什么事的)、token描述、过期时间、repository范围和权限(想要正常执行clone、pull等操作就得给代码读写权限)。
这个resource owner我也不知道除了自己还能选谁,我就是给自己用的,所以还没有仔细研究。
- 生成personal access token后点击复制即可(注意这个token只会生成一次,在token详情界面中也不能复制)
在token详情界面中可以续期。