DEV Community

i am message
i am message

Posted on

Set up github work/company email on mac together with your personal github account

Here’s a clean step-by-step outline to generate and add an SSH key from your macbook to GitHub, using your company email your_personal_company_email as the identifier.

🛠️ Add SSH Key to GitHub – Step-by-Step

1. Generate the SSH Key

In terminal, run:

ssh-keygen -t rsa -b 4096 -C "your_personal_company_email"
Enter fullscreen mode Exit fullscreen mode

This command generates a new SSH key pair (used to securely authenticate with services like GitHub).

  • Explanation of Each Part:
Part Meaning
ssh-keygen The command to generate a new SSH key.
-t rsa Specifies the type of key to create. rsa is a widely used algorithm.
-b 4096 Sets the bit size of the key. 4096 bits is stronger than the default 2048.
-C "your_email@example.com" Adds a label (comment) to the key file so you can identify it later — usually your email.
  • When prompted:

    • Enter file name: give it a custom name like your_name-company (e.g. /Users/mac/.ssh/your_name-company)
    • Press Enter to skip passphrase (or set one if you prefer extra security)

2. Add the Key to SSH Agent

The SSH agent is a background program that holds your private SSH keys in memory. This means you won’t need to enter your passphrase every time you use the key (e.g., when pushing to GitHub).

First, start the SSH agent:

eval "$(ssh-agent -s)"
Enter fullscreen mode Exit fullscreen mode

This command starts the SSH agent and sets up the necessary environment variables so your terminal can communicate with it.

Next, add your private key to the agent:

ssh-add ~/.ssh/your_name-company
Enter fullscreen mode Exit fullscreen mode

Replace your_name-company with the actual name of your private key file (not the .pub one).

Once added, the agent will remember your key for the current session, allowing passwordless SSH/Git operations.


3. Copy the Public Key to Clipboard

Run:

pbcopy < ~/.ssh/your_name-company.pub
Enter fullscreen mode Exit fullscreen mode

This copies the SSH key to your clipboard.


4. Add the Key to GitHub

  1. Go to: https://github.com/settings/ssh/new
  2. Title: e.g. MacBook - Company
  3. Key: paste the copied content (Cmd+V)
  4. Click “Add SSH Key”

5. Update ~/.ssh/config File

Open it:

nano ~/.ssh/config
Enter fullscreen mode Exit fullscreen mode

Add this block:

# GitHub for company
Host github.com-company
  HostName github.com
  User git
  IdentityFile ~/.ssh/your_name-company
  IdentitiesOnly yes
Enter fullscreen mode Exit fullscreen mode

Save:

  • Press Ctrl + O, then Enter to save
  • Press Ctrl + X to exit

6. Test the Connection

Run:

ssh -T git@github.com-company
Enter fullscreen mode Exit fullscreen mode

Expected:

Hi your-username! You've successfully authenticated...
Enter fullscreen mode Exit fullscreen mode

7. Clone the Repo Using the Alias

Use this to clone:

git clone git@github.com-company:company/repository.git
Enter fullscreen mode Exit fullscreen mode

📚 Sources

Top comments (0)