美文网首页
GitLab and SSH keys[Make a recor

GitLab and SSH keys[Make a recor

作者: yilinUnique | 来源:发表于2018-04-24 16:20 被阅读0次

    Git is a distributed version control system, which means you can work locally but you can also share or "push" your changes to other servers. Before you can push your changes to a GitLab server you need a secure communication channel for sharing information.
    The SSH protocol provides this security and allows you to authenticate to the GitLab remote server without supplying your username or password each time.
    more>>

    Step 1

    Before generating a new SSH key pair check if your system already has one at the default location by opening a shell, or Command Prompt on Windows, and running the following command:

    Windows Command Prompt:

    type %userprofile%\.ssh\id_rsa.pub
    

    Git Bash on Windows / GNU/Linux / macOS / PowerShell:

    cat ~/.ssh/id_rsa.pub
    

    If you see a string starting with ssh-rsa you already have an SSH key pair and you can skip the generate portion of the next section and skip to the copy to clipboard step. If you don't see the string or would like to generate a SSH key pair with a custom name continue onto the next step.

    My Work Laptop already has an SSH key pair but the e-mail form of it doesn't conform to our project, so I generate a new custom one.


    Step 2

    2.1 To generate a new SSH key pair, use the following command:

    Git Bash on Windows / GNU/Linux / macOS:

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

    2.2 Next, you will be prompted to input a file path to save your SSH key pair to. If you don't already have an SSH key pair use the suggested path by pressing enter. Using the suggested path will normally allow your SSH client to automatically use the SSH key pair with no additional configuration.

    I used the default suggested path because I don't need to config other things for it.

    2.3 Once you have input a file path you will be prompted to input a password to secure your SSH key pair. It is a best practice to use a password for an SSH key pair, but it is not required and you can skip creating a password by pressing enter.
    If you want to change the password of your SSH key pair, you can use

    ssh-keygen -p <keyname>
    

    I don't know why I can't input anything when I come to this step... So I skip it.

    2.4 The next step is to copy the public SSH key as we will need it afterwards.

    Windows Command Line:

    type %userprofile%\.ssh\id_rsa.pub | clip
    

    Git Bash on Windows / Windows PowerShell:

    cat ~/.ssh/id_rsa.pub | clip
    

    2.5 The final step is to add your public SSH key to GitLab.

    Profile Settings > SSH Keys > Paste > Add key

    2.6 Optionally you can test your setup by running

    ssh -T git@example.com 
    

    (replacing example.com with your GitLab domain) and verifying that you receive a Welcome to GitLab message.

    Welcome to GitLab, CHEN

    相关文章

      网友评论

          本文标题:GitLab and SSH keys[Make a recor

          本文链接:https://www.haomeiwen.com/subject/xoyjlftx.html