Skip to content

git账号切换,提交代码被拒绝的问题 #144

@ahua52

Description

@ahua52

场景问题

今天把家里的电脑拿来用,我自己在这台电脑上提交代码,报Permission denied的错误

问题解决步骤

1.设置Git的user name和email

git config --global user.name "yourname"
git config --global user.email "youremail"

2.生成SSH密钥

查看是否已经有了ssh密钥:cd ~/.ssh
如果没有密钥则不会有此文件夹,有则备份删除
生存密钥:
ssh-keygen -t rsa -C “haiyan.xu.vip@gmail.com”
按3个回车,密码为空。
Your identification has been saved in /home/tekkub/.ssh/id_rsa.
Your public key has been saved in /home/tekkub/.ssh/id_rsa.pub.
The key fingerprint is:
………………
最后得到了两个文件:id_rsaid_rsa.pub
添加密钥到ssh:ssh-add 文件名,需要之前输入密码.

在github上添加ssh密钥,这要添加的是“id_rsa.pub”里面的公钥。
打开https://github.com/,在设置中添加密钥

到这,问题还没解决 git push 还是 还是报拒绝的错误

3.查看账号信息

git config --list 返回的信息也是正确的

4.验证权限

ssh -T git@githun.com
返回的信息是
Hi lut! You've successfully authenticated, but GitHub does not provide shell access.

5.再一次 设置远程路径

git remote set-url origin git@github.com:tinper-bee/formControl.git
然后再git push 我的代码 上github上看发现还是原来的账号提交的代码(因之前下载下来的代码是用之前的账号)
我在本地代码再做一次修改 然后提交 这次github上的账号显示正常

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions