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

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.

Related

zsh terminal can't open config?

Hello I am very new to using zsh terminal and am trying to set up my SSH key with github. According to this tutorial I have to open my /.ssh/config file and add my key. But after creating the file using touch ~/.ssh/config and then using the open command, the terminal goes opaque as if executing but then nothing happens. Please help!
Adding your key to your ~/.ssh/config (using, as noted, a text editor) is only needed to:
reference a private SSH key which is not a default one (as listed in "Checking for existing SSH keys"), like id_rsa, id_ecdsa, or id_ed25519.
using a shorter SSH URL
Meaning your config file can look like:
Host gh
Hostname github.com
User git
IdentityFile ~/.ssh/my_private_key
IdentitiesOnly yes
And your SSH URL becomes gh:me/myRepository. (no more git#github.com:...)
You can test your SSH key with ssh -Tv gh.

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).

Github configuration id_rsa password

For the github configuration, I have completed the steps of
1.) creating new SSH keys
2.) entering my id_rsa.pub key and thus adding the key
But during the testing stage of testing, after I entered
user$ ssh -T git#github.com
A new window (outside the terminal) opens up asking : Enter your password for "id_rsa". Where can I find this password. FYI, I am using a Mac OS 10.5.8
Even after I entered:
user$ ssh -vT git#github.com
The same new window opens up asking for the "id_rsa" password.
Please help.
While creating your ssh key in step 1), make sure to enter no passphrase for it. Otherwise the setup will be more complicated as you need to use something like ssh-agent to enter the password automatically for you.

Permission denied (public key) during fetch from GitHub with Jenkins user on Ubuntu

Here is my setup:
Jenkins is running on my linux machine as 'jenkins' user.
I have generated a ssh key-pair as described in Linux - Setup Git, for the 'jenkins' user.
When I sudo su jenkins and try ssh -vT git#github.com, I am always asked my passphrase, but I am always eventually authenicated. (the verbose option shows which key is used, among others).
I could clone my repo from GitHub using jenkins:
Thusly:
jenkins#alpm:~/jobs/test git/workspace$ git pull
Enter passphrase for key '/var/lib/jenkins/.ssh/id*_rsa':
Already up-to-date.
Up to this point I have followed the instructions to the letter. The problem is that the Jenkins job fails with the following error:
status code 128:
stdout:
stderr: Permission denied (publickey).
fatal: The remote end hung up unexpectedly
This is same error as I get when I typo the passphrase (but of course, Jenkins does not ask me for the passphrase). The following pages:
GitHub - SSH Issues
Using SSH Agent Forwarding
indicate to me that ssh-agent could help remember the passphrase, which it does when I am using my own user, but not the jenkins id. Note that while running as my normal user yields:
echo "$SSH_AUTH_SOCK"
/tmp/keyring-nQlwf9/ssh
While running the same command as my 'jenkins' yields nothing (not even permission denied)
My understanding of the problem is that the passphrase is not remembered.
Do you have any idea?
Shall I start a ssh-agent or key ring manager for the jenkins user? How?
Or is ssh forwarding suitable when forwarding to the same machine?
Any brighter idea?
ps: I never sudo gitted, I always used jenkins or my user account (as mentioned in this SO post - Ubuntu/GitHub SSH Key Issue)
Since nobody wrote the answer from the comments for several months, I will quickly do so.
There are 2 possible problems/solutions:
id_rsa created with wrong user
Create id_rsa as the jenkins user (see hudson cannot fetch from git repository)
Leave passphrase empty
To summarise what must be done on the Jenkins server:
# 1. Create the folder containing the SSH keys if necessary
if [ ! -e ~jenkins/.ssh ]; then mkdir ~jenkins/.ssh; fi
cd ~jenkins/.ssh/
# 2. Create the SSH pair of keys
# The comment will help to identify the SSH key on target systems
ssh-keygen -C "jenkins" -f ~jenkins/.ssh/id_rsa -P ""
# 3. Assign the proper access rights
chown -R jenkins ~jenkins/.ssh/
chmod 700 ~jenkins/.ssh
chmod 600 ~jenkins/.ssh/*
Remember:
Please keep the default "id_rsa" name when generating the keys, as other such as "id_rsa_jenkins" won't work, even if correctly set up.
Do not use a passphrase for your key
Check that the public key (id_rsa.pub) has been uploaded on the git server (GitHub, Bitbucket, etc). Once done, test your SSH key by running: ssh -vvv git#github.com (change address according to your git server)
I got around this problem by simply leaving the passphrase empty when creating the keys.
I would add that if you created the keys by hand, they might still be owned by you and not readable by jenkins, try:
sudo chown jenkins -R /var/lib/jenkins/.ssh/*
To check are the following:
if the right public key (id_rsa.pub) is uploaded to the git-server.
jenkins user will access to github -> to CHECK if the right private key (id_rsa) is copied to /var/lib/jenkins/.ssh/
if the known_hosts file is created inside ~/.ssh folder. Try ssh -vvv git#github.com to see debug logs. If thing goes well, github.com will be added to known_hosts.
if the permission of id_rsa is set to 755 (chmod 755 id_rsa)
After all checks -> try ssh -vvv git#github.com
Dont try to do config in jenkins until ssh works!
If you are running jenkins as a service in windows, you need to verify the user running the service. If you created the keys using the user "MACHINENAME\user", change the service so the user running it can match
For Mac users, the issue can be solved by removing the existing keys and creating new Private and Public Keys by following these steps:
1.Remove all Public and Private keys located at /Users/Username/.ssh
2.Remove all the credentials saved under the Credentials tab in Jenkins.
3.Remove the existing Public SSH keys defined in the Github Repository Settings.
4.Create new SSH keys (private and public: id_rsa and id_rsa.pub) by following the steps from https://confluence.atlassian.com/bitbucketserver/creating-ssh-keys-776639788.html#CreatingSSHkeys-CreatinganSSHkeyonLinux&MacOSX
5.Set the newly created public SSH key (id_rsa.pub) in Github or an equivalent Repository Settings.
6.In Jenkins,create new credentials by adding the private SSH key(id_rsa) for your Github username.
7.The Error should be removed now.
keys need to generated from jenkins user.
sudo su jenkins
ssh-keygen
once the key is generated, it should be added as ssh key in bitbucket or github.