DEV Community

Arshan Nawaz
Arshan Nawaz

Posted on

Add SSH to Github

Step 1: Generate a new SSH key

ssh-keygen -t ed25519 -C "email@example.com" -f ~/.ssh/key-path

Enter fullscreen mode Exit fullscreen mode

Step 2: Display the public key (use this to add to GitHub)

cat ~/.ssh/key-path.pub

Enter fullscreen mode Exit fullscreen mode

Step 3: Start the SSH agent

eval "$(ssh-agent -s)"

Enter fullscreen mode Exit fullscreen mode

Step 4: Add the new key to the SSH agent

ssh-add ~/.ssh/key-path

Enter fullscreen mode Exit fullscreen mode

Step 5: Edit the SSH config file to specify which key to use for GitHub

nano ~/.ssh/config

Enter fullscreen mode Exit fullscreen mode

Inside the config file, add the following:

Host github.com
   HostName github.com
  User git
   IdentityFile ~/.ssh/key-path
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

Step 7: Test the connection to GitHub

ssh -T git@github.com

Enter fullscreen mode Exit fullscreen mode

Top comments (0)