GitHub仓库的SSH权限配置

    xiaoxiao2024-12-14  69

    步骤1:Generating a new SSH key

    $ ssh-keygen -t rsa -b 4096 -C "your_email@example.com"

    > Enter file in which to save the key (/Users/lr/.ssh/id_rsa): /Users/your/.ssh/github.com/your/id_rsa

    > Enter passphrase (empty for no passphrase): [Press enter]

    > Enter same passphrase again: [Press enter]

    Your identification has been saved in /Users/your/.ssh/github.com/your/id_rsa.

    Your public key has been saved in /Users/your/.ssh/github.com/your/id_rsa.pub.

    步骤2:Adding your SSH key to the ssh-agent

    $ ssh -T git@github.com

    Permission denied (publickey).

    $ ssh -vT git@github.com

    OpenSSH_7.7p1, LibreSSL 2.7.3

    $ ssh-add -K /Users/your/.ssh/github.com/your/id_rsa

    Identity added: id_rsa (id_rsa)

    $ ssh -T git@github.com

    Hi your! You've successfully authenticated, but GitHub does not provide shell access.

    步骤3:Adding your SSH key to GitHub.com

    登录:github.com

    打开:settings > SSH and GPG keys

    将公钥id_rsa.pub ( /Users/your/.ssh/github.com/your/id_rsa.pub ) 拷贝至New SSH Key中。

    步骤4:Using SourceTree to access repositories of GitHub.com

    在github.com新建远程仓库,用SourceTree克隆代码,然后修改代码,最后推送到远程仓库。

    如果成功,则证明一切符合预期;

    如果不成功,则根据具体情况进行调整。

    常见问题:

    SSH权限问题:Permissions 0644 for '/Users/your/.ssh/id_rsa' are too open.

    chmod 0600 /Users/your/.ssh/id_rsa

    GIT模式问题:使用了gitlab远程仓库的http地址,导致无权限推送新代码至远程仓库。

    在SourceTree将克隆的本地仓库转换成SSH,再执行远程发布。

    温馨提示:

    同一个github账号,可以使用不同的ssh密钥以对应不同的仓库需要。

    所以,当你将远程仓库克隆为本地仓库后,应及时对本地仓库进行自定义配置:

    > 用户信息(用户名和邮件)

    > .gitignore文件(忽略的文件和文件夹)

    在本地仓库目录下执行命令:git config --list,可以查看当前仓库的配置信息

    最新回复(0)