How do I generate new ssh-key for my new gitlab account?

后端 未结 4 687
无人共我
无人共我 2020-12-15 11:07

I have two Gitlab accounts. On my old account I added an ssh-key that is located in ~/.ssh/id_rsa.pub on my computer.

<
4条回答
  •  再見小時候
    2020-12-15 11:17

    I would recommend a second key, for now without passphrase:

    ssh-keygen -t rsa -C "your_email@example.com" -P "" -q -f ~/.ssh/gitlab_rsa
    

    That will create (without any prompt) ~/.ssh/gitlab_rsa (private key) and ~/.ssh/gitlab_rsa.pub (public key)

    You need to register that second gitlab_rsa.pub public key to your second GitLab account.

    Navigate to the 'SSH Keys' tab in your 'Profile Settings'. Paste your key in the 'Key' section and give it a relevant 'Title'.

    Then add a ~/.ssh/config file with:

    Host gitlab_rsa
        HostName gitlab.com
        User git
        PreferredAuthentications publickey
        IdentityFile /home//.ssh/gitlab_rsa
    

    Finally, you can clone any GitLab repo as your second identity with:

    git clone gitlab_rsa:/
    

    That will be replaced automatically with git@gitlab.com:/ and will use your second key.

提交回复
热议问题