Skip to content

Instantly share code, notes, and snippets.

@dipaish
Last active October 24, 2024 12:39
Show Gist options
  • Save dipaish/588766dd87254fdf67c2e719adc1923c to your computer and use it in GitHub Desktop.
Save dipaish/588766dd87254fdf67c2e719adc1923c to your computer and use it in GitHub Desktop.
Setting up SSH Keys in GitHub

Docker Task - 2024

Step 1: Create a a Project Directory

It is always good to create a dedicated directory for your Docker Compose project. This helps in organizing your project files.

  1. In the learning portfolio 3 (root directory), create a directory named dockerTasks

  2. Get into the directory dockerTasks

  3. Create a Docker Compose File (docker-compose.yml)

  4. Add the following configuration to your docker-compose.yml file. Each section includes comments, do accordingly and create the services required. Pay attention to the indents. You are required to fix them also.

services:  # Defines the services (containers) to be run.
    service1:  # Service name; name the service as firstname_lastname_db
        image:   # Use the mysql 8.0 version
        container_name: mysql_container  # Assigns a custom name to the container.
        environment:  # Sets environment variables for configuration.
            MYSQL_ROOT_PASSWORD: ${MYSQL_PASSWORD}: # You don't want to type the password in this file, so create a .env file and type your password there. MYSQL_PASSWORD=yourpassword
        ports:  # Maps container ports to host ports.
            - ":"  # Maps host port 6029 to container port 3306.
    volumes:  # Mounts host directories or volumes into the container.
      - your_data:/var/lib/mysql  # Persists MySQL data.
    service2:  # Service name; name the service as firstname_adminer
        image:   # Use the adminer latest version
        container_name: adminer_container  # Assigns a custom name to the container.
        ports:  # Maps container ports to host ports.
            - ":"  # Maps host port 8888 to container port 8080.
        depends_on:  # Expresses dependency between services that is specify the database service name as above
      - service1
  volumes:
    your_data:
   
  1. Build the services and open localhost:8888

You should type the username as root and the password as in the .env file to login. Make sure that you are able to login. In the server name option when trying to login: servername is the name of the service for database. eg. firstname_lastname_db

  1. Take the screenshot from the docker dashboard. Push all these files that you have created also to your remote repo for the third learning portfolio.

  2. Follow inclass instructions to set up the GitHub codespace and include the required screenshot.

Congratulations, you have compelted your lp3. Submit the link to the Moodle page and write your group name group 1 or group 2 like you did earlier.

Using SSH Keys with GitHub

With SSH keys, you can securely interact with GitHub repositories (like cloning, pushing, and pulling changes). It does not require you to repeatedly enter your username and password.

How to store and use SSH keys with GitHub?

Step 1. Generate your SSH Key

  • Open your terminal, powershell or git bash
  • Run the following command to generate a new SSH key.
ssh-keygen -t ed25519 -C "[email protected]"

Follow the prompts to save the key to the default location and use the default name. You may set a passphrase for an added layer of security. However, if you're automating tasks, keep in mind that the passphrase may cause issues by requiring manual input during execution.

The above command will generate 2 keys.

1. Public Key

This key is meant to be shared with others, like GitHub or any other service you're authenticating with. It's safe to upload or share publicly. GitHub will use this key to verify that you have the matching private key.

Example: id_ed25519.pub

ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIEXAMPLEKEY3MDK7F9tYPbSfg3TxPmX [email protected]
2. Private Key

This key should be kept secure and never shared with anyone. It's stored on your computer and is used to prove your identity when connecting to a service that has your corresponding public key.

Example: id_ed25519

-----BEGIN OPENSSH PRIVATE KEY-----
b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAgEEXAMPLEPRIVATEKEYwPCZPQ
MORECHARACTERSOFTHEKEYqpvri/EpHVfgvDRP0UKNScgD9J0Kmr3Jhv0stf1o
-----END OPENSSH PRIVATE KEY-----

Default Location for SSH Keys

By default, when you generate an SSH key using the ssh-keygen command, the keys are stored in your home directory under the .ssh folder.

Public Key: ~/.ssh/id_ed25519.pub Private Key: ~/.ssh/id_ed25519

Step 2. Add the SSH key to GitHub

  1. Copy the SSH public key: The following command displays your public key. Copy it.
cat ~/.ssh/id_ed25519.pub
  1. Log in to GitHub and go to your account settings.

  2. Navigate to SSH and GPG keys.

  3. Click New SSH key, give it a title (e.g., "My Laptop"), and paste the SSH public key.

  4. Click Add SSH key.

Use SSH to clone a repository

  1. Copy the SSH URL of the repository. It looks something like this:
[email protected]:username/repository.git
  1. Use the following command to clone the repo:
git clone [email protected]:username/repository.git
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment