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

后端 未结 4 686
无人共我
无人共我 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/<you>/.ssh/gitlab_rsa
    

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

    git clone gitlab_rsa:<yourSecondAccount>/<yourRepo.git>
    

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

    0 讨论(0)
  • 2020-12-15 11:34

    Generate SSH please follow below steps.

    Open Git Bash on you machine

    Enter the below command to genarate

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

    Generating public/private rsa key pair. Enter a file in which to save the key (/c/Users/you/.ssh/id_rsa):Press enter Enter passphrase (empty for no passphrase): Type a passphrase Enter same passphrase again: Type passphrase again

    Once enter the confirm passphrase, will get confirmation message.

    go to the gitpair.pub file location and right click open with notepad. copy the code and past the in the below text box, your email will pick automatically in the title box. then click add key.

    0 讨论(0)
  • 2020-12-15 11:39

    Generate a new key pair with:

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

    It will ask you to enter a name for the key file:

     Enter a file in which to save the key (/home/you/.ssh/id_rsa): [Press enter]
    

    Choose something different such as /Users/you/.ssh/gitlab_rsa

    Then when you need it add this key to your ssh-agent with:

    ssh-add ~/.ssh/gitlab_rsa
    

    If you want a permanent access you can edit your ~/.ssh/config file with:

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

    Refer to this article for further details.

    0 讨论(0)
  • 2020-12-15 11:43

    You need to create the file ~/.ssh/config to define which key should use for every domain.

    Create that file with nano and paste your configuration:

    nano ~/.ssh/config
    

    And add:

    Host your-gitlab.com
        HostName your-gitlab.com
        IdentityFile ~/.ssh/your-gitlab-privkey
    
    0 讨论(0)
提交回复
热议问题