Creating SSH Keys and Cloning a Github Repository

Step 1: Open the Terminal

  • Mac: Press Command + Space, type “Terminal” and press Enter.
  • Windows: Press Windows key + R, type cmd and press Enter.

Step 2: Check for Existing SSH Keys

  1. In the terminal, type the following command and press Enter

    ls -al ~/.ssh
  2. f you see files like id_ed25519 and id_ed25519.pub, you already have SSH keys. If not, continue to the next step.

Step 3: Generate a New SSH Key

  1. In the terminal, type the following command and press Enter:

    ssh-keygen -t ed25519 -C "your_email@example.com"

    Replace your_email@example.com with your email address.

  2. When prompted to “Enter a file in which to save the key,” press Enter. This accepts the default file location.

  3. Next, you will be asked to enter a passphrase. You can press Enter to skip this step, but it is recommended to enter a passphrase for added security. If you enter a passphrase, you will need to enter it each time you use the SSH key.

Step 4: Add Your SSH Key to the SSH-Agent

  1. Start the SSH agent by typing the following command and pressing Enter:

    eval "$(ssh-agent -s)"
  2. Add your SSH key to the agent by typing the following command and pressing Enter:

    ssh-add --apple-use-keychain ~/.ssh/id_ed25519

    This command will add your key and save the passphrase to the macOS keychain. For Windows, use the command:

    ssh-add ~/.ssh/id_ed25519

Step 5: Add the SSH Key to Your GitHub Account

  1. Copy the SSH key to your clipboard by typing the following command and pressing Enter:

    cat ~/.ssh/id_ed25519.pub

    This will display your public SSH key in the terminal.

  2. Select and copy the entire key.

  3. Open your web browser and go to GitHub (or your Git repository provider).

  4. Log in to your account and go to the SSH keys section:

    • GitHub: Click on your profile picture, go to “Settings,” then “SSH and GPG keys,” and click “New SSH key.”
    • GitLab: Click on your profile picture, go to “Settings,” then “SSH Keys,” and click “Add SSH Key.”
  5. In the “Title” field, enter a descriptive name for the SSH key (e.g., “My Computer”).

  6. Paste your SSH key into the “Key” field.

  7. Click “Add SSH key” or “Add key” to save it.

Step 6: Clone the Repository

  1. Go to the repository you want to clone on GitHub (or your Git repository provider).

  2. Click the “Code” button and make sure “SSH” is selected.

  3. Copy the repository SSH URL.

  4. In the terminal, navigate to the directory where you want to clone the repository by typing cd followed by the directory path and pressing Enter. For example:

    cd /path/to/your/directory
  5. Clone the repository by typing the following command and pressing Enter:

    git clone git@github.com:username/repository.git
     

    Replace username and repository with the appropriate names.

Done!

You have successfully created an ed25519 SSH key, added it to your GitHub account, and cloned a repository to your local machine.