0% found this document useful (0 votes)
5 views

Git Tips

Uploaded by

bole.balic
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Git Tips

Uploaded by

bole.balic
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

Adding an SSH key to your GitHub account is a straightforward process that involves

generating an SSH key on your local machine (if you don’t already have one) and
then adding it to your GitHub account. Here’s how you can do it:

### Step 1: Generate an SSH Key

1. **Open a terminal** (or Git Bash on Windows).

2. **Generate a new SSH key**:

sh

Copy code

`ssh-keygen -t ed25519 -C "[email protected]"`

If you are using an older system that does not support the `ed25519` algorithm,
you can use:

sh

Copy code

`ssh-keygen -t rsa -b 4096 -C "[email protected]"`

3. **When prompted to "Enter a file in which to save the key"**, press Enter to
accept the default file location.

4. **At the prompt**, type a secure passphrase. This step is optional, but
recommended.

### Step 2: Add the SSH Key to the SSH Agent

1. **Start the SSH agent in the background**:

sh

Copy code

`eval "$(ssh-agent -s)"`

2. **Add your SSH private key to the SSH agent**:

sh

Copy code

`ssh-add ~/.ssh/id_ed25519`

If you used a different filename for your key, replace `id_ed25519` with the
appropriate filename.

### Step 3: Add the SSH Key to Your GitHub Account

1. **Copy the SSH key to your clipboard**:

sh
Copy code

`cat ~/.ssh/id_ed25519.pub`

Select and copy the entire output.

Alternatively, you can use:

sh

Copy code

`pbcopy < ~/.ssh/id_ed25519.pub # macOS`

sh

Copy code

`clip < ~/.ssh/id_ed25519.pub # Windows`

2. **Go to GitHub** and log in to your account.

3. **Navigate to your SSH and GPG keys settings**:

- In the upper-right corner of any page, click your profile photo, then click
**Settings**.
- In the left sidebar, click **SSH and GPG keys**.
4. **Click "New SSH key"**.

5. **In the "Title" field**, add a descriptive label for the new key. For example,
if you're using a personal Mac, you might call this key "Personal MacBook".

6. **Paste your key into the "Key" field**.

7. **Click "Add SSH key"**.

8. **Confirm your GitHub password** if prompted.

### Step 4: Test Your Connection

1. **Open a terminal**.

2. **Test the SSH connection**:

sh

Copy code

`ssh -T [email protected]`

3. You should see a message like this:

sh

Copy code

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

If you see this message, you have successfully added your SSH key to your GitHub
account.

### Additional Tips

- **Use multiple SSH keys**: If you use different SSH keys for different purposes
(e.g., work and personal), you can manage multiple keys using the SSH configuration
file (`~/.ssh/config`).

- **Backup your SSH keys**: Ensure you have backups of your SSH keys stored
securely, as losing them can mean losing access to your repositories.

Following these steps will secure your GitHub interactions with SSH, providing a
safer and more convenient way to manage your repositories.

You might also like