Skip to content

Instantly share code, notes, and snippets.

@eagafonov
Last active March 15, 2017 11:52
Show Gist options
  • Save eagafonov/f6c8b8b5d244c957b534c201d378338f to your computer and use it in GitHub Desktop.
Save eagafonov/f6c8b8b5d244c957b534c201d378338f to your computer and use it in GitHub Desktop.
GitLab access instructions (template)

How to get an access to you-gitlab-URL

There are just 3 simple steps to start pushing some stuff to gitlab using SSH

  1. Sign-up or request new account
  2. Generate SSH keys
  3. Upload SSH key to GitLab
  4. Update ~/.ssh/config for non-standart SSH port

Register new account usging sing-up form

Sign-up form is available at URL

sign-up may be disabled by evil paranoid admins Request account as described below

Request GitLab account

Send a request via transport to contact

***Update with correct conatnct info ***

Upload SSH key

  1. Generate SSH keys using ssh-keygen (skip this step if you want to use existing SSH keys)
  2. Post content of id_rsa.pub to https://gitlab.example.com/profile/keys

Important note for Windows user

Avoid using Putty's puttygen utility to generate keys unless you can export keys in correct format

TL;DR; Putty's keys format is incompartible (see below for details)

Set SSH access port

SSH port may be changed from 22 to some other value due to security reasons. You need to specify correct SSH port either in ~/.ssh/config file (globally) or specified it in URL (for each git repo you are going to push into)

editing ~/.ssh/config

Add or update section in ~/.ssh/config

Host gitlab.example.com
  User git
  Port 2222

Specify port in URL

For example GIT repo is available as [email protected]:foo/bar and the SSH port is 2222

An alternate URL is ssh://[email protected]:2222/foo/bar

Advanced topics

Separate SSH key pair for git access

You may generate separate shs keys to access each gitlab server.

  1. generate ssh keys with non-standard name on first question of ssh-keygen. Leave passphrase empty by hitting Enter.

     #> ssh-keygen 
     Generating public/private rsa key pair.
     Enter file in which to save the key (/home/username/.ssh/id_rsa): /home/username/.ssh/id_rsa_gitlab_example  
     Enter passphrase (empty for no passphrase): 
     Enter same passphrase again: 
     Your identification has been saved in /home/username/.ssh/id_rsa_gitlab_example.
     Your public key has been saved in /home/username/.ssh/id_rsa_gitlab_example.pub.
     The key fingerprint is:
     69:64:64:71:64:69:64:6b:66:61:69:64:63:6c:69:70 username@localhost
     The key's randomart image is:
     +---[RSA 2048]----+
     |                 |
     |                 |
     |    (\___/)      |
     |    (='.'=)      |
     |    (")_(")      |
     |                 |
     |                 |
     |                 |
     |                 |
     +-----------------+
    
  2. Post content of public key /home/username/.ssh/id_rsa_gitlab_example.pub to GitLab as described above.

  3. Update ~/.ssh/config with IdentityFile (note that it must point to private key, not public)

     Host gitlab.example.com
         User git
         Port 2222
         IdentityFile ~/.ssh/id_rsa_gitlab_example # <--- there is not .pub at the end
    

How to check that SSH keys are accepted by GitLab

you may check if keys are accepted using ssh

    #> ssh -p 2222 -I /path/to/private/key [email protected]

    PTY allocation request failed on channel 0
    Welcome to GitLab, Luke Skywalker!
    Connection to gitlab.example.com closed.
    
    #>_

The message above states the SSH connection is established and the user is authenticated. Note that GitLab welcomes the actial owner of SSH key, not a generic git user

You don't get shell promt, just welcome message. If you are asked for git password you keys does not match.

PuTTY's keys are not accepted

Git client uses OpenSSL/OpenSSH (and keys in PKCS#8 PEM) so Putty's key format ('traditional' PEM) is incompatible. You may use openssl rsa to convert but it better to use OpenSSH to generate keys i first place

More details here

You can export private key in OpenSSH format using puttygen's menu Conversations->Export OpenSSH key

License

This text is available under terms of WTFPL

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment