How do I know which ssh key is used in my github account? - github

When I go to the SSH keys page in my GitHub account, I see a key whose identity starts with "c5:42:08:9d:39:22..."
On my computer, in the ".ssh" folder, I have several files that look like public SSH keys, but none of them contains a string similar to the above. For example, one
of the files "id_rsa.pub" contains a string that starts with "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABA..." there are other similar files that probably represent different keys.
How can I identify which of the files, if any, represents the actual key that is in my github account?

"c5:42:08:9d:39:22..." isn't the key, but rather the key's fingerprint. You can see your key's fingerprint using ssh-keygen:
ssh-keygen -lf ~/.ssh/id_rsa
Where
-l means we want to see the key's fingerprint
-f ~/.ssh/id_rsa is a path to the key whose fingerprint we want to see
On older versions of OpenSSH, you may need to also specify that you want the SHA256 fingerprint rather than another hash like MD5, since SHA256 is what GitHub shows in its web interface:
ssh-keygen -lf ~/.ssh/id_rsa -E sha256
You should get the same fingerprint from the public part as from the private part of the keypair.

Related

How to add a passphrase for ssh key after its been created?

Is generating a new one necessary, or is there a way to go back and add a passphrase?
I have generated an ssh key, but would like to go back and add a passphrase. I haven't linked it to my github yet. Is there any way to do this?
As explained here, you can add a passphrase to an existing private key with:
cd ~/.ssh
ssh-keygen -o -p -f keyfile
But you can also link that to GitHub immediately: adding a passphrase (encrypting the private key) does not change the public key you would register to your GitHub profile.
The public key will remain the same, before and after you add a passphrase to your local private key.

How to link ssh key to ssh agent and push files to github account

I need help on how to link my ssh key to ssh agent.
On generating the key which was saved at (mykeys) which i can view, the codes belows where generated in the bash terminal window.
$ ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/c/Users/user/.ssh/id_rsa): mykeys
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in mykeys
Your public key has been saved in mykeys.pub
The key fingerprint is:
SHA256:/DEK8rKIlb+j1aEVWL3jYG5I0dcuYk4DoKuxrHiGOws user#OshimiriAtata1
The error I keep getting for all my trials is:
No such file or directory
I have followed the instructions I get on various YouTube videos I am watching currently, but cannot figure out what the issue is.
I have tried the following:
ssh-add \~/.ssh/id_1895
ssh-add ..ssh/id_1895`your text`
ssh-add .ssh\\id_1895
ssh-add \~/.ssh/id_rsa`your text`
ssh-add \~/.Henry/.Data-set/.ssh_mykeys
All to no avail.
Please can you help me?
Following "Generating a new SSH key and adding it to the ssh-agent", the command would be:
sh-add C:\path\to\mykeys
And you would need a ~/.ssh/config file with
Host gh
Hostname github.com
User git
IdentityFile C:\path\to\mykeys
Test if this works with: ssh -Tv gh, you should see a welcome message similar to:
Hi *****!
You've successfully authenticated, but GitHub does not provide shell access.
You can use the URL with commands like:
git clone gh:myGitHubUser/myRepository
I ran into this same problem, it kept putting the file on my desktop. I discovered this when I went to search on the bottom left of my Windows machine and typed in the name of my file, in your case "mykeys".
Literally followed the same exact steps you did and it still put it on my desktop.

Error "The authenticity of host 'github.com' can't be established. RSA key fingerprint "

I use my project at work, but I would like to work with him from home as I can log into my home machine to work with my project.
However, from home, I see the following message:
The authenticity of host 'github.com (ip)' can't be established.
RSA key fingerprint is SHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8.
Are you sure you want to continue connecting (yes/no)?
How can I get past it?
You should simply be able to answer 'yes', which will update your ~/.ssh/known_hosts file.
A better approach, to avoid any MITM (Man-In-The-Middle) attack, would be (as commented below by Mamsds) to verify Github's public key first (see "GitHub's SSH key fingerprints") and, if you find a match, then you can answer 'yes'.
Example:
ssh-keyscan -t ecdsa github.com 2>&1 |ssh-keygen -lf -
256 SHA256:p2QAMXNIC1TJYWeIOttrVc98/R1BUFWu3/LiyKgUfQM github.com (ECDSA)
After that, you can use a GitHub SSH URL (provided you have generated the SSH public/private keys, and registered the public one to your GitHub profile)
Note: the ssh key generation should use the base64 old PEM format (option -m PEM), rather than the new current 70 chars OpenSSH one.
See "What is the correct format for private key in Credentials":
ssh-keygen -m PEM -t rsa -P "" -f afile
That or you can switch to an HTTPS URL.
As you are attempting to connect to Github using SSH for the first time (no existing entry for Github in ~/.ssh/known_hosts yet), you are being asked to verify the key fingerprint of the remote host. Because, if an intruder host represents itself as a Github server, it's RSA fingerprint will be different from that of a GitHub server fingerprint.
You have two options.
You may just accept, considering you don't care about the authenticity of the remote host (Github in this case), or,
You may verify that you are actually getting connected to a Github server, by matching the RSA fingerprint you are presented to (in the prompt), with GitHub's SSH key fingerprints in base64 format.
The latter option is usually more preferable.
Just add Github fingerprint to known hosts this way:
mkdir -p ~/.ssh
ssh-keyscan -t rsa github.com >> ~/.ssh/known_hosts
Use one of the following two solutions:
1) Set up the SSH key
Follow the steps discussed on this GitHub help page.
https://help.github.com/en/github/authenticating-to-github/connecting-to-github-with-ssh
2) Clone using git with HTTPS
Type (copy/paste) the following commands in a terminal on the machine where you would like to clone the repository
git config --global url."https://github.com/".insteadOf git#github.com:
git config --global url."https://".insteadOf git://
You can revert this change using the following commands
git config --global url."git#github.com:".insteadOf https://github.com/
git config --global url."git://".insteadOf https://
Try these steps:
Open Git Bash
Check for existing SSH keys:
$ ls -al ~/.ssh
If you already have them, you will see:
id_rsa.pub
id_ecdsa.pub
id_ed25519.pub
If you don't, generate one (Press Enter to accept the default file location):
$ ssh-keygen -t rsa -b 4096 -C "your_email#example.com"
To copy the key to clipboard:
$ clip < ~/.ssh/id_rsa.pub
Go to your account on Github/Settings/SSH and GPG keys/New SSH key
Paste your key there
Next, type:
$ git remote
If you see origin, remove it:
$ git remote remove origin
Continue with the last 2 steps provided on GitHub repo page...
$ git remote add origin git#github.com:USERNAME/REPONAME.git
$ git push -u origin master
Refresh your GitHub repo page
Voila!
1- Create SSH key
if you don't have the ssh-key create it like this:
ssh-keygen -t rsa -b 4096 -C "youremail#example.com"
2- Check your SSH key
For this go to your folder ssh, example:
cd ~/.ssh
after that, run this command line : ls
if you have the files: id_rsa, id_rsa.pub so the all is good
now you need to copy your id_rsa.pub ! (⚠️ NOT the id_rsa)
for this run cat id_rsa.pub and copy the result
3- Github / Gitlab
Go to your github / gitlab.
Follow the step by your hosting:
github: Click on your profile -> Settings -> SSH and GPG Keys -> New SSH key
gitlab: Click on your profile -> preferences -> SSH keys
past your id_rsa.pub that you have already copied !
4- If you have already did it and it's already not working ??
When your enter your ssh-key in github / gitlab your key have a Expiration date so you just need to change it
That it ! Have a good work 😀
You just need to type yes and it will work, for more information you can refer to the Official Github documentation. This will give an output saying
Hi <username>! You've successfully authenticated, but GitHub does not provide shell access.

Generating a new project on Moovweb

I'm having a tough time creating a new project for Moovweb. I'm getting this error, but don't see where to add SSH keys within moovweb:
"ERROR: None of the SSH keys on this machine are associated with your moovweb account. Please use moov login, then try again."
Usually this happens if your ssh key is named something other than the default id_rsa
You can see what keys are associated with the ssh-agent by typing this command
ssh-add -l
If the key you have uploaded to Moovweb is not in that list, you can add it with
ssh-add <path to key>
For example,
ssh-add ~/.ssh/github_rsa

Why do I need to run `ssh-add` in my Powershell profile?

In my Microsoft.PowerShell_profile.ps1 document, I've had to add ssh-add ~/.ssh/github_rsa following the poshgit examples in order for it to connect to my GitHub repos.
# Load posh-git example profile
. 'C:\tools\poshgit\dahlbyk-posh-git-8aecd99\profile.example.ps1'
ssh-add ~/.ssh/github_rsa
If I don't have that in my profile, I Github gives me permissions errors when I try to connect.
If I do it manually, it will work for the entire duration of my desktop session, but as soon as I reboot my computer, I need to re-run the command.
Why doesn't poshgit and ssh-add remember the rsa that I've added? It seems wrong to have to re-add it every time.
It's because your rsa key is not the default name ( id_rsa ) so you either need to use ssh-add (which adds it to a running service that remembers the key decrypted with your passphrase) or just add an entry into your ~\.shh\config
~\.ssh\config (create or edit):
Host github.com
HostName github.com
User git
IdentityFile ~/.ssh/github_rsa
Or, if github is the only thing you use ssh keys for, just rename the key to id_rsa and then git (well ssh.exe) will find it for you automatically AND poshgit will ssh-add it for you (to handle passphrases).