Step 1: Generate a new SSH key
ssh-keygen -t ed25519 -C "email@example.com" -f ~/.ssh/key-path
Step 2: Display the public key (use this to add to GitHub)
cat ~/.ssh/key-path.pub
Step 3: Start the SSH agent
eval "$(ssh-agent -s)"
Step 4: Add the new key to the SSH agent
ssh-add ~/.ssh/key-path
Step 5: Edit the SSH config file to specify which key to use for GitHub
nano ~/.ssh/config
Inside the config file, add the following:
Host github.com
HostName github.com
User git
IdentityFile ~/.ssh/key-path
Step 6: Set appropriate permissions for the .ssh directory and the keys
chmod 700 ~/.ssh # Permissions for the .ssh folder
chmod 600 ~/.ssh/key-path # Permissions for the private key
chmod 644 ~/.ssh/key-path.pub # Permissions for the public key
Step 7: Test the connection to GitHub
ssh -T git@github.com
Top comments (0)