2. Account Setup & SSH Configuration

To begin using GitHub, you need to set up a free account and establish a secure connection between your local computer and GitHub's cloud servers. In this chapter, we will discuss creating your account and configuring **SSH keys** for passwordless authentication.

1. Creating a GitHub Account

  1. Visit the official portal at github.com.
  2. Click "Sign up" in the top-right corner.
  3. Follow the interactive prompts to enter your email, create a secure password, and pick a unique username.
  4. Complete the verification puzzle and enter the launch code sent to your email.

2. HTTPS vs. SSH Authentication

When pushing or pulling code from GitHub, your local Git needs to authenticate itself. GitHub offers two main protocols:

  • HTTPS: Easy to configure. You log in via a browser window pop-up. However, it requires frequent browser re-authentication or token setups.
  • SSH (Secure Shell): Extremely secure, industry-standard authentication. Uses cryptographic keys. Once set up, it requires **no password entry** when pulling or pushing code!

3. Setting Up SSH Authentication (Step-by-Step)

SSH works via a pair of keys: a **public key** (which you upload to GitHub) and a **private key** (which stays safely hidden on your local machine).

Step 1: Check for existing SSH keys

Open your Terminal (macOS/Linux) or Git Bash (Windows) and type:

ls -al ~/.ssh

If you see files named id_rsa.pub or id_ed25519.pub, you already have keys and can skip to Step 3.

Step 2: Generate a new SSH Key Pair

Run the following command, replacing the email with your GitHub account email address:

ssh-keygen -t ed25519 -C "your.email@example.com"

When prompted to "Enter a file in which to save the key", press **Enter** to accept the default location. You can optionally set a passphrase for added security, or press Enter twice for a passwordless key.

Step 3: Add your SSH key to the SSH-Agent

Start the ssh-agent in the background and add your newly created private key:

# Start agent
eval "$(ssh-agent -s)"

# Add private key
ssh-add ~/.ssh/id_ed25519

Step 4: Add the Public Key to your GitHub Profile

  1. Copy the public key contents to your clipboard.
    # On Windows (Git Bash)
    clip < ~/.ssh/id_ed25519.pub
    
    # On macOS
    pbcopy < ~/.ssh/id_ed25519.pub
    
    # On Linux (requires xclip)
    xclip -sel clip < ~/.ssh/id_ed25519.pub
  2. Log in to GitHub and click your profile picture in the top-right, then select Settings.
  3. On the left sidebar, click "SSH and GPG keys".
  4. Click the green "New SSH key" button.
  5. Give your key a descriptive name (e.g., "My Work Laptop"), select **Key type as "Authentication"**, and paste your public key in the text field.
  6. Click "Add SSH key" (you may be prompted to enter your GitHub password to verify).

Step 5: Test Your Connection

Go back to your terminal and run:

ssh -T git@github.com

You will see a warning like: "The authenticity of host 'github.com' can't be established...". Type yes and press Enter. If everything is correct, you will see a message like:

Success! "Hi username! You've successfully authenticated, but GitHub does not provide shell access."