How do I provide SSH keys to GitHub Actions so that pip can install from a git repo? [duplicate] - github

This question already has answers here:
Git error: "Host Key Verification Failed" when connecting to remote repository
(30 answers)
Closed 1 year ago.
I'd like to pip install a library from a private GitHub repository in a GitHub Actions job. I can install it on my computer just fine because I've configured GitHub to accept the SSH key. But how do I give an SSH key to a GitHub Actions runner?
On my computer, this works fine:
python -m pip install "git+ssh://git#github.com/ORG/LIBRARY.git#main#egg=SOMETHING&subdirectory=SOMETHING"
Collecting LIBRARY
Cloning ssh://****#github.com/ORG/LIBRARY.git (to revision main) to /tmp/pip-install-_kw52ce5/LIBRARY_35c4fb5cf6a64e30914beaec4a768bd1
Installing build dependencies ... done
...
Successfully built LIBRARY-0.1.1
I changed the name of the library, organization, and directories for privacy. Documentation for pip installations from GitHub repos are here.
I have tried this guide with this GitHub action with no luck. In GitHub Actions, I get this error message:
Step 15/20 : RUN pip install -r requirements.txt
---> Running in 5ece3eb6572e
Collecting LIBRARY# git+ssh://git#github.com/ORG/LIBRARY.git#main#egg=SOMETHING&subdirectory=SOMETHING
Cloning ssh://****#github.com/ORG/LIBRARY.git (to revision main) to /tmp/pip-install-ohx86p2h/LIBRARY_2972ab1296ce45afa73bbb3c5a036bd1
Running command git clone -q 'ssh://****#github.com/ORG/LIBRARY.git' /tmp/pip-install-ohx86p2h/LIBRARY_2972ab1296ce45afa73bbb3c5a036bd1
Host key verification failed.
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
How do I give an SSH key to a GitHub Actions runner?

I think the "Host key verification failed" points to an issue with the ~/.ssh/known_hosts file. Typically, the first time you connect to a host via ssh you are prompted with something similar to:
The authenticity of host 'domain.com (a.b.c.d)' can't be established.
RSA key fingerprint is XX:XX:...:XX.
Are you sure you want to continue connecting (yes/no)?
When you answer yes, the host key is automatically added to the known_hosts file. You can manually add the host key to the known_hosts file of the user that is running your Github Actions:
Get the host key directly from a github admin or once logged into github.com (more secure - highly suggest).
use ssh-keyscan -H github.com >> ~/.ssh/known_hosts

Related

Error in the checkout of a Github using Subversion with SSH - Linux Command line

Github recently enforced a no password rule with their repository access. I can't do two factor authentication, so, I am stuck with SSH keys. I want to use subversion, but when I try to checkout my repo, using:
svn co "svn+ssh://git#github.com/Oiubrab/ozzymandais.git"
I get the error:
Invalid command: 'git#github.com svnserve -t'
You appear to be using ssh to clone a git:// URL.
Make sure your core.gitProxy config option and the
GIT_PROXY_COMMAND environment variable are NOT set.
svn: E170013: Unable to connect to a repository at URL 'svn+ssh://git#github.com/Oiubrab/ozzymandais.git'
svn: E210002: To better debug SSH connection problems, remove the -q option from 'ssh' in the [tunnels] section of your Subversion configuration file.
svn: E210002: Network connection closed unexpectedly
From the research I've done, I think I need to edit the /home/user/.subversion/config file, but i have no idea how and there is no documentation as to how to use svn with github with ssh. I have setup an ssh key and popped it on my github account. I just need to know how to setup the subversion tunnel to github.
I don't think that github supports the svnserve protocol.
AFAIK, you should generate a personal access token (PAT) in GitHub and use it as a password in the Subversion client. I.e., enter your PAT when the client prompts you for a password.

Cannot use git to clone in remote web server

I have created a Github repo to where I push my local changes using Git Bash, without any problems. I can also use Git Bash to connect to my remote web server (shared hosting) and navigate to the folder where I want to clone my Laravel site.
This is where the problems begin. When I do
$ git clone git#github.com:myusername/mylaravelsite.git
I get the error message:
Permission denied (publickey)
After some searching for a solution I found that I should make sure that I have a key by doing this:
$ eval "$(ssh-agent -s)"
Which gave this answer:
Agent pid 122372
Then according to the instructions I should do this
$ ssh-add -l
Which gave me this message:
The agent has no identities
Reading up a bit more I try to add the key again by doing
$ssh-keygen -t rsa
...which generated a key pair that I added with ssh-add, I was prompted for a passphrase which I entered twice.
Now, I still get Permission denied (publickey) when I try to access my github repo with ssh. I should also mention that I have created a new SSH key at the github account where I pasted the key I created (I opened .ssh/id_rsa-pub with notepad and copied the content).
What more can I try?
Finally found the answer in case anyone else has the same problem. It turns out that the public key also must exist in the remote web server (in the .ssh folder I uploaded the same rsa_id and rsa_id.pub files, that I created locally), not only locally and in the Github account.
Once I had figured that out and uploaded those files to the webserver, it worked to clone my github repo :-).

AWS-CPP-SDK download from git fails

I'd like to install the c++ sdk on my ec2 instance. The bash command to do this is given on this page: https://docs.aws.amazon.com/sdk-for-cpp/v1/developer-guide/setup.html
"To build the SDK from source"
...
"Clone with Git: git clone git#github.com:aws/aws-sdk-cpp.git"
I downloaded git on my instance and tried this command and get these errors:
"The authenticity of host 'github.com (192.30.253.112)' can't be established.
RSA key fingerprint is SHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8.
RSA key fingerprint is MD5:16:27:ac:a5:76:28:2d:36:63:1b:56:4d:eb:df:a6:48.
Warning: Permanently added 'github.com,192.30.253.112' (RSA) to the list of known hosts.
Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights and the repository exists."
If I can't resolve this, then I need to do a direct download. Can I do a Direct download via curl? I'd like to be able to get a fresh download every time I launch a new instance so that I pick up all the new code updates.
The given download(checkout)instruction is based on the assumption that you are using ssh to access Github. You should set up ssh key on Github to make that work.
Otherwise, you can use Https to check it out: git clone https://github.com/aws/aws-sdk-cpp.git

How to use multiple Git SSH keys on Eclipse?

I looked several answers and forums for a solution but I could not find a single one that works.
I have this scenario:
Eclipse Luna Service Release 2 (4.4.2)
Ubuntu 14.04 x64
Two ssh keys on my ~/.ssh folder
Two bitbucket accounts (one for personal projects and one for enterprise)
A git repository only accessible with my primary key (~/.ssh/id_rsa)
A git repository only accessible with my secondary key (~/.ssh/other)
I created a ~/.ssh/config file with the contents:
Host bitbucket bitbucket.org
Hostname bitbucket.org
IdentityFile ~/.ssh/id_rsa
IdentityFile ~/.ssh/other
User git
And for the sake of sanity I added the second key using ssh-add as well. Running ssh-add -l lists both keys.
When using the command line, all git commands work like a charm, with both repositories. But when using Eclipse, I always get the Invalid remote: origin error when trying to clone or pull from the repository with the secondary key:
Caused by: org.eclipse.jgit.errors.NoRemoteRepositoryException: git#bitbucket.org:myuser/myrepository.git: conq: repository access denied.
I added the secondary key at Window > Preferences > Network Connections > SSH2 > Private keys, and set the GIT_SSH environment variable to point to my ssh executable:
$echo $GIT_SSH
/usr/bin/ssh
I've restarted Eclipse and even the OS several times, with no luck.
Since I can use git from the command line without problems, I tend to believe there's something wrong with Eclipse.
How to use multiple Git SSH keys on Eclipse? Or how to force Eclipse to use my secondary key on a single project?
Host bitbucket bitbucket.org? You don't declare multiple entry names on one Host section.
I would expect to see in a ssh config file declaring multiple keys:
Host bitbucketuserA
Hostname bitbucket.org
IdentityFile ~/.ssh/id_rsa
User git
Host bitbucketuserB
Hostname bitbucket.org
IdentityFile ~/.ssh/other
User git
And you would use ssh url like
bitbucketuserA:userA/myrepo1
bitbucketuserB:userB/myrepo2
(this is similar to what I suggested for "How to work on personal GitHub repo from office computer whose SSH key is already added to a work related GitHub account?")

Could not read from remote repository

I have received the following error multiple times:
Could not read remote repository. Please make sure you have the correct access rights and the repository exists.
I am very confused about how to remedy this error.
Make sure you are using the correct SSH keys/usernames on both your GitHub account and your local machine. Here's how you can
do that on GitHub
Also, you might consider using an alternative Git manager. I've never heard of Aptana, but I do know that GitHub has an awesome GUI program for managing your repositories.
In the future, this is all much easier and more streamlined on Linux/Unix operating systems like Ubuntu. Ubuntu is geared towards developers and has things like Git and SSH installed correctly by default.
I had the exact same issue with a private repo.
Cloning through the same error both through https and ssh
Then I made a commit through github (simply updated the README.md with an empty line)
Surprisingly enough, this resolved the issue. It would be nice to know why though!
I had the same problem - it was caused by me using the SSH key instead of the HTTPS URL. I created my repository by importing a project via Intellij and it must have pushed via HTTPS.
Assuming you have done the proper SSH keys configuration according to github's instructions it might be a problem of pull with https and later pushing with git+ssh
to make it more clear
if you have used https to pull
git pull https://github.com/user/repo.git
then you have changed remote URL
git remote set-url origin git+ssh://github.com/user/repo.git
and tried to push after some changes and commits
git push origin master
you might get this error it happened to me
erase the local repository and re-clone using git+ssh
git pull git+ssh://github.com/user/repo.git
and now your push should work
ssh-add -A resolved my issue in MacOS Sierra 10.12.6.
I had no problem both for public and private repo before.
Today I tried to clone or git pull for private repo, but it hit the above issues.
After search around, this is the perfect solution for me.
On Windows open file:
C:\Users\<USER_NAME>\.ssh\config
You should have your host defined in the "config" file:
host gitlab.com
HostName gitlab.com
IdentityFile ~/.ssh/id_rsa_user_private_key
host bitbucket.org
HostName bitbucket.org
IdentityFile ~/.ssh/id_rsa_user_private_key
host github.com
HostName github.com
IdentityFile ~/.ssh/id_rsa_user_private_key
Try these 3 Simple Steps:
It's pretty straight forward. See the 3 step summary of the links below.
Check for the existence of SSH keys. If one exists, then great: you can use it. If not, then you will have to create one.
You will need to add the ssh key to the ssh-agent. If the agent is snoozing on the job, then you will need to wake the agent by writing this to your console/terminal: eval $(ssh-agent -s). Then you can simply add the key,
Try pushing your repository. Hopefully it should work.
I had same issue on my private Ubuntu server using ssh.
My workaround solution was:
open shell on my private server
git init --bare /path/<myapp>.git
and then, from my developer laptop
git push <remote_repo> <local branch>
has finally worked well.
PS:
I've never tried, but remote repo with https seems working better than ssh.
I hope this help.
In addition to setting the identity files in the ssh config, I also had to set the git remote to the right user - complete solution in https://www.keybits.net/post/automatically-use-correct-ssh-key-for-remote-git-repo/
vi ~/.ssh/config
Host github.com-myuser
HostName github.com
User git
IdentityFile ~/.ssh/mykey
I made sure I had this identity file loaded with ssh-add -l
ssh-add -l
4096 SHA256:XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX mykey (RSA)
Then I set my remote to include the right user
git remote set-url origin git#github.com-myuser:myuser/myrepo.git
Then the push worked
git push -u origin master
Enumerating objects: 146, done.
Counting objects: 100% (146/146), done.
Delta compression using up to 4 threads
Compressing objects: 100% (144/144), done.
Writing objects: 100% (146/146), 9.71 MiB | 7.48 MiB/s, done.
Total 146 (delta 10), reused 0 (delta 0)
remote: Resolving deltas: 100% (10/10), done.
To git#github.com-myuser:myuser/myrepo.git
* [new branch] master -> master
Voila
If you have updated you OSX recently you have to call ssh-add -A. Have a look at this answer: https://apple.stackexchange.com/questions/254468/macos-sierra-doesn-t-seem-to-remember-ssh-keys-between-reboots
Installing a root/CA Certificate
Given a CA certificate file foo.crt, follow these steps to install it on Ubuntu:
Create a directory for extra CA certificates in /usr/share/ca-certificates:
sudo mkdir /usr/share/ca-certificates/extra
Copy the CA .crt file to this directory:
sudo cp foo.crt /usr/share/ca-certificates/extra/foo.crt
Let Ubuntu add the .crt file's path relative to /usr/share/ca-certificates to /etc/ca-certificates.conf:
sudo dpkg-reconfigure ca-certificates
This is an old post, but this is they only thing that I found that worked.
I also had the exact same error and for some reason restarting my pc solved the error. Maybe it works for somone else too :P
If it's a public repo, just clone using https. No need to use passwords or setup SSH keys.
if you want to push/pull any repository from local to remote(git hub)
first checkout
$ git push https://<git-hub url>
working fine with username and passwd credential
$ git push git#<git-hub url>
fail
Could not read remote repository. Please make sure you have the correct access rights and the repository exists.
this means you need to add id_rsa.pub to authorized_keys
goto
$ cd /home/admin/.ssh
$ls
$vi authorized_keys
add id_rsa keys(n no of keys you can add)
ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAIEA0KJDLOiiXj9XdMxiCT9KvaKfuxFQi+CIiklaN5hHsNgYOu7TijqyONEu5fONLoAo/cshLa+KuargyTrtizwcP4TPcTXZhhJrM0GUDJragw7SMVIs/5xJBGAyHKJ1YUMGO7+nJTmsCLx6PFOlQYveuriiVVCCZerGCLH+UtSXK3z+l7hx9NiDg3/ylOLc3f3SLxrJKn0gMTgK7BHJFXo4PguuPjWZLVdUDX+XKiqtT2n4IsYs6N9qVFG3zUgNlEjZM47NK/ytAC0max98pK+QNzsuaQOo/IShJ1TOw5wwScflPArVJ2AyROqAe7cfQg7q12I9olASFd3U5NazfZCTYAvWA1kz9UZEWLJ1Br1XOkPqOleMM8KCp/PXzz8H0kISkMIji0/QuiZOPEBsKlszXjlALcXR8Mg1uiZVWy48i9JheyXyj1ToCj6cPScpgFHp3DAGSlKKbE1EFaVfeeyGAnHESlnDDg3Gq5xSsB9Okqm3V5t8GpFaJbV68BxQ4BK6HJ21A3CinV4LdV3hR/OBUbDG2EcI+ZKRDjlpJuu4YU= stace#pretend-machine
ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAIEAywWhrwq4FjHt+UuwZcZePxtjtZOENFpOjufycaYso2nTlzNwnAQEQRfbqsUxKVtOtGxgApIkUvjRIjNBdJE6iOzvBXZhhJrM0GUDJragw7SMVIs/5xJBGAyHKJ1YUMGO7+nJTmsCLx6PFOlQYveuriiVVCCZerGCLH+UtSXK3z+l7hx9NiDg3/ylOLc3f3SLxrJKn0gMTgK7BHJFXo4PguuPjWZLVdUDX+XKiqtT2n4IsYs6N9qVFG3zUgNlEjZM47NK/ytAC0max98pK+QNzsuaQOo/IShJ1TOw5wwScflPArVJ2AyROqAe7cfQg7q12I9olASFd3U5NazfZCTYAvWA1kz9UZEWLJ1Br1XOkPqOleMM8KCp/PXzz8H0kISkMIji0/QuiZOPEBsKlszXjlALcXR8Mg1uiZVWy48i9JheyXyj1ToCj6cPScpgFHp3DAGSlKKbE1EFaVfeeyGAnHESuXC9wkSeFZCEyMJ+RgJxMkBXNZmyycbwsSqAeGJpMEUDlwzu2GD0obBz0HXqg9J1Xallop5AVDKfeszZcc= stace#another-machine
:wq!
goto github-->settings--->ssh---->add new key---->id_rsa.pub
$git push git#<git-hub url>
I had the same issue with Pycharm on Ubuntu the solution is to use https instead of SSH
for example :
https://github.com/Bedo1212/myrepo.git
If you're using SSH, make sure you're using a network that allows SSH. Most public networks allow only HTTP(S) traffic.
Hi my problem was that my client did not ask if I recognized the key. Opening a terminal and doing ssh -T git#github.com worked. The response in the terminal asked if I wanted to add the key, I said yes and after that, my client worked fine
I had a similar issue, Until I realized, I was running my machine through a proxy address for my internet connection and it happens to close the host connection. This could be one of the few reasons too.
For me, I had followed all the steps mentioned in Adding new ssh key and rest of the auxiliary links related to this issue.
But the issue was network access. Solution - using VPN to access my Github Enterprise. (in my case Georgia Tech VPN for github.gatech.edu)
In my case, I generated new key pairs but forgot to update public key in github.com (settings).
A simple solution to this is delete the old ssh key from github/gitlab and add the same key again. This is easy work around and you have to hussle with anything