已经因为不能用户名密码push很久没有用github了,但是考虑到代码的版本管理问题,还是再回到git管理代码的方法来。
今天在服务区push的时候,遇到问题,
[$] <( (git)-[main]-)> git push
Username for 'https://github.com': weiyw16
Password for 'https://weiyw16@github.com':
remote: Support for password authentication was removed on August 13, 2021. Please use a personal access token instead.
remote: Please see https://github.blog/2020-12-15-token-authentication-requirements-for-git-operations/ for more information.
fatal: Authentication failed for 'https://github.com/weiyw16/SeekWeights.git/'
所以打算改成ssh key的方法登录。
一、生成密钥
首先,生成新的用来github的共钥和私钥,
ssh-keygen -t rsa -b 4096 -C "yourgithub-email"
第一步设置id_rsa的时候注意不要把以前的密钥覆盖了。
如果重命名之后,需要在 ~/.ssh/config加入这句话
Host github.com git@github.com
IdentityFile ~/.ssh/id_rsa_newname
回到github的设置页面,增加ssh key
注意key中不要有换行/空格!
二、修改git的连接方式
最后,重新更改git目录下的remote origin地址
1 删除原来的地址
git remote rm origin
2 添加新的git开头的remote地址
git remote add origin git@github.com:your-project.git
3 更新stream
git push --set-upstream origin main
之后就可以用密钥push代码了。