When managing separate professional and personal repositories on a single macOS instance, isolating authentication credentials prevents permission conflicts. Begin by navigating to the secure shell directory.
cd ~/.ssh
Creating a New Key Pair
Generate a new key pair using the Ed25519 algorithm for improved security. Specify a unique filename to prevent overwriting existing default keys like id_rsa.
ssh-keygen -t ed25519 -C "developer@example.org" -f id_ed25519_work
During execution, the system will prompt for a passphrase. Enter a secure string twice; this protects the private key during usage.
Registering with the SSH Agent
macOS manages SSH identities through the local agent. Register the new private key to ensure it is available for authentication requetss.
ssh-add ~/.ssh/id_ed25519_work
Verify the identity is loaded by listing curent keys.
ssh-add -l
Configuring Host Aliases
To automatically select the correct key for specific repositories, define host rules in the SSH configuration file. Create or edit ~/.ssh/config.
Host github-work
HostName github.com
User git
IdentityFile ~/.ssh/id_ed25519_work
AddKeysToAgent yes
When cloning or pushing, use the alias github-work instead of the standard github.com in the remote URL.
Deploying the Public Key
Extract the public key content and copy it directly to the clipboard for easy pasting into provider settings.
cat ~/.ssh/id_ed25519_work.pub | pbcopy
Navigate to the SSH keys section of your Git provider account and paste the contents.
Verifying Connectivity
Test the authentication handshake using the configured host alias or standard endpoint.
ssh -T git@github.com
A successful response confirms the identity is recognized without granting shell access.