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"
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)
-
Enter file name: give it a custom name like
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)"
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
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
This copies the SSH key to your clipboard.
4. Add the Key to GitHub
- Go to: https://github.com/settings/ssh/new
-
Title: e.g.
MacBook - Company
- Key: paste the copied content (Cmd+V)
- Click “Add SSH Key”
5. Update ~/.ssh/config
File
Open it:
nano ~/.ssh/config
Add this block:
# GitHub for company
Host github.com-company
HostName github.com
User git
IdentityFile ~/.ssh/your_name-company
IdentitiesOnly yes
Save:
- Press
Ctrl + O
, thenEnter
to save - Press
Ctrl + X
to exit
6. Test the Connection
Run:
ssh -T git@github.com-company
Expected:
Hi your-username! You've successfully authenticated...
7. Clone the Repo Using the Alias
Use this to clone:
git clone git@github.com-company:company/repository.git
Top comments (0)