Connecting to GitLab

GitLab doesn't use username/password authentication for Git interaction, but rather identifies users by SSH key. The following is a short summary of how to set that up. More details as https://gitlab.com/help/ssh/README.

  1. On the machine to be used for development, generate SSH public/private keys.
    • ssh-keygen on Linux or Git Bash in Git for Windows
    • Be sure to include a meaningful comment (-C <comment>), usually including your username, the name of the machine on which you're creating the key, and perhaps the date.
    • E.g.:

      ssh-keygen -t rsa -C "pittmara@oregonstate.edu_2018-07-06_GitLab" -f ~/.ssh/id_rsa_gitlab
  2. Print the public key to the screen:

    cat ~/.ssh/id_rsa_gitlab.pub
    
  3. Add your key to GitLab
    1. Login to GitLab
    2. Click your profile picture in the top right corner and click Settings.
    3. Select SSH Keys from the sidebar on the left.
    4. Copy the contents of your public SSH key (printed in the previous step) and paste it into the Key field and click Add Key.
  4. Open your ~/.ssh/config file:

    Host gitlab.com
        ForwardX11 no
        RSAAuthentication yes 
        IdentityFile ~/.ssh/id_rsa_gitlab
    

    where ~/.ssh/id_rsa_gitlab is the path to your private SSH key you've created to use with GitLab.
  5. Now you can interact with all GitLab projects you own and/or have permission to access simply by using the git command. No user name or password need be entered--GitLab will use git@gitlab.com for the username and identify your GitLab account name by your SSH key. You can test the connection with the command ssh git@gitlab.com. It should log in to GitLab, issue a welcome message, and close the connection.

    pittmara@flip2:~ $ ssh git@gitlab.com
    PTY allocation request failed on channel 0
    Welcome to GitLab, @randallpittman!
    Connection to gitlab.com closed.