Git - Set up SSH keys

If you want to use SSH: git remote set-url origin git@github.com:USERNAME/REPOSITORY.git

Check to see if there are existing ssh keys in your computer

https://docs.github.com/en/authentication/connecting-to-github-with-ssh/checking-for-existing-ssh-keys

In Windows,

  1. Open Git Bash.
  2. Enter ls -al ~/.ssh to see if existing SSH keys are present.
    $ ls -al ~/.ssh
    
    Lists the files in your .ssh directory, if they exist

Generate new ssh keys

And then run this:

ssh-keygen -t rsa -b 4096 -C "explorer436@tutanota.com"

(When you’re prompted to Enter a file in which to save the key, press Enter. This accepts the default file location.) Now add this SSH ket to bitbucket server.

Files with names other than id_rsa may not be automatically picked up by the ssh agent in your computer.

If you want to add an SSH key generated from Git console to the ssh-agent in your computer :

You might need to start ssh-agent before you run the ssh-add command:

eval `ssh-agent -s`

or

eval $(ssh-agent)

Add your SSH private key to the ssh-agent using the following command:

ssh-add  ~/Downloads/CloudForgeGitSSHKeys/id_rsa

(this should point to the location of the private key file)

If you see the follwing error,

Permissions 0664 for '/home/explorer436/.ssh/id_rsa' are too open.
It is required that your private key files are NOT accessible by others.
This private key will be ignored.

fix the permissions by using these:

Keys need to be only readable by you: chmod 400 ~/.ssh/id_rsa

If Keys need to be read-writable by you: chmod 600 ~/.ssh/id_rsa

600 appears to be fine as well (in fact better in most cases, because you don’t need to change file permissions later to edit it).


Links to this note