Create a new repository, or reuse an existing one.

Generating a new SSH key
  • Open Git Bash
  • paste the text below, substituting in your email address
$ ssh-keygen -t ed25519 -C "your_email@example.com"
Note: If you are using a legacy system that doesn't support the 
Ed25519 algorithm, use:
$ ssh-keygen -t rsa -b 4096 -C "your_email@example.com"

This creates a new ssh key, using the provided email as a label.

> Generating public/private ed25519 key pair.

the default file location is :

/c/Users/you/.ssh/id_ed25519
Adding your SSH key to your Git-account

Copy the contents of the file ~/.ssh/id_ed25519.pub  ( in Windows: /c:/users/you/.ssh/id_ed25519.pub) to your SSH keys in your Git account settings ( example: https://github.com/settings/keys).

In the upper-right corner of any page, click your profile photo, then click Settings.
Settings icon in the user bar
In the user settings sidebar, click SSH and GPG keys.

Authentication keys
Click New SSH key or Add SSH key.

SSH Key button
In the "Title" field, add a descriptive label for the new key.
 For example, if you're using a personal Mac, you might call this
 key "Personal MacBook Air".

Paste your key into the "Key" field.

The key field
Click Add SSH key.
The Add key button
If prompted, confirm your Git password.
Sudo mode dialog
Testing if work !!

Test SSH key:

$ ssh -T git@github.com
Hi developius! You've successfully authenticated, but GitHub does not provide shell access.

Change directory into the local clone of your repository (if you’re not already there) and run:

git remote set-url origin git@github.com:username/your-repository.git

Now try editing a file (try the README) and then do:

$ git commit -m "Update README.md"
$ git push

If successful , you should not be asked for a username or password. Your SSH key is correctly configured.

multiple ssh keys in .ssh folder?

Yes you can have different ssh keys. for different repository or even different git tools ( exple: gitlab & github).

What you can do is set up a ~/.ssh/config file in which you can associate the right private key with the right host, as explained here.

I – Using multiple repositories on one server

In the server’s SSH configuration file (usually ~/.ssh/config), add an alias entry for each repository. For example:

Host github.com-repo-0
        Hostname github.com
        IdentityFile=/home/user/.ssh/repo-0_deploy_key

Host github.com-repo-1
        Hostname github.com
        IdentityFile=/home/user/.ssh/repo-1_deploy_key
  • Host github.com-repo-0 – The repository’s alias.
  • Hostname github.com – Configures the hostname to use with the alias.
  • IdentityFile=/home/user/.ssh/repo-0_deploy_key – Assigns a private key to the alias.

You can then use the hostname’s alias to interact with the repository using SSH, which will use the unique deploy key assigned to that alias. For example:

$ git clone git@github.com-repo-1:OWNER/repo-1.git

By Shabazz

Software Engineer, MCSD, Web developer & Angular specialist

Leave a Reply

Your email address will not be published. Required fields are marked *