Skip to content

Instantly share code, notes, and snippets.

@carloscodingroadtrip
Last active July 12, 2020 07:42
Show Gist options
  • Save carloscodingroadtrip/20b5e7725f0c6bc3f2ff4bb5c3492a1f to your computer and use it in GitHub Desktop.
Save carloscodingroadtrip/20b5e7725f0c6bc3f2ff4bb5c3492a1f to your computer and use it in GitHub Desktop.
Gitlab

Setting up SSH Keys for Gitlab

( Mac & Windows Instructions )

Step 1 - Generate SSH Keys

Generate SSH Key by running the following command:

Mac Users Windows Users
Open your terminal open the Git Bash terminal

In your terminal, run the following command:

Mac Users
ssh-keygen -t ed25519 -C "<your_email_address>"
Windows Users
cd ~
cd /c/Users/<username>/.ssh
ssh-keygen -t ed25519 -C "<your_email_address>"

You’ll see a response similar to:

Generating public/private rsa key pair.
Enter file in which to save the key (/home/user/.ssh/id_ed25519):<press ENTER>

PRESS ENTER and just accept the suggested file and directory.

**Press ENTER again to leave the passphrase empty. DO NOT ENTER A PASSPHRASE

**Press ENTER again to confirm an EMPTY PASSPHRASE.

If successful, you’ll see confirmation of where the ssh-keygen command saved your identification and private key.

To confirm and view existing SSH keys on your machine, run the command :

Run the following command:

ls -al ~/.ssh

You should see something similar like the image below: alt text (Above are the SSH Keys on my laptop - YOUR FILE NAMES ARE NOT GOING TO BE THE SAME )

Step 2 - Copy the SSH key to a text format and ADD the key to Gitlab

We will copy our public SSH key to a location that saves information in text format.

In your terminal, run the following command:

Mac Users
pbcopy < ~/.ssh/id_ed25519.pub
Windows Users
cat id_ed25519.pub | clip

YOU WILL NOT SEE ANYTHING HAPPENING AT THE TERMINAL

**But at this time the contents of the SSH key are in memory in the clipboard and we are ready to add it to GitLab **

Open Google Chrome (or browser you use),

  • Navigate to http://gitlab.com and sign in.

  • Select your avatar in the upper right corner, and click Settings

  • Menu on the left, Click SSH Keys

  • Paste the key that you copied into the Key text box.

  • Make sure your key includes a descriptive name in the Title text box, such as Work Laptop or Home Workstation.

  • Click the Add key button.

See image below on how to paste the key into the text box:

alt text

Mac Users Windows Users
Cmd+V Ctrl+V

Step 3 - Clone Class Repository to your local computer

You should now be able to clone the class repo, and perform git pull to fetch new data into your computer.

Getting the <repo_url>:

  • you will need to login to GitLab,
  • navigate to Projects
  • Click the "RU-HOU-PROJECT-NAME"
  • Click the blue button "Clone", and copy the SSH URL

alt text

Now back to the terminal, we will clone the repository for the first time to a dedicated directory:

Both Mac & Windows

We will create a directory inside our Documents folder called "DATABOOTCAMP-MATERIAL" (you can change the name if you'd like), and inside that folder we will clone the class repository.

cd ~
cd Documents
mkdir <DATABOOTCAMP-MATERIAL>
cd <DATABOOTCAMP-MATERIAL>
git clone <repo_url_link>

Gitlab "READ MORE : How to clone a repository documentation"

Step 4 - Before class, fetch new data to your local computer.

To pull/fetch new data to your local computer, navigate to the folder location we specified above:

cd Documents/<DATABOOTCAMP-MATERIAL>/<ru-hou-some-long-folder-name> 
git pull

|

ADDITIONAL FIXES

ISSUE: Passphrase being asked everytime you perform a 'git pull or git push'

NOTE: You will need to remember the passphrase you created for your ssh key. If you've accidentally created a passphrase for a git SSH key that requires you to type it for each git pull and git push you can just reset the password to blank by following this next sequence.

For Mac
ssh-keygen -p -f <ssh_key_filename>
For Windows
### Make sure to navigate to the folder location where the ssh keys are stored in your PC

cd /c/Users/<username>/.ssh

### then view the list of files on the .ssh folder

ls -la

### Once you know the filename for the SSH key you created with a passphrase and 
### it is the one you added to Gitlab, you can run the following command:

ssh-keygen -p -f <ssh_key_filename>

Enter file in which the key is (/home/username/.ssh/<ssh_key_filename>): press Enter

Enter old passphrase: <old_passphrase>

Enter new passphrase (empty for no passphrase): <press_enter_to_leave_empty>

Enter same passphrase again: <press_enter_to_leave_empty>

You should now see a response like: Your identification has been saved with the new passphrase.

DONE!

You should now be ready to perform git push or git pull from GitLab without being asked for a passphrase every time!

ADDITIONAL RESOURCES

GitLab and SSH keys

Gitlab Help

Github Help

Medium Article - How to setup multiple SSH Keys

Cloning Repos

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