How to add public ssh keys to private repos? - github

I am trying to set up a private GitHub repo which I need to allow two people to see it. They provided me with their public SSH keys.
I've created the repo.
So as I understood I should put their public SSH keys in the deploy key (my-private-repo > settings > deploy keys).
I did it; however, for both SSH keys I got the following error:
![1]: https://ibb.co/PG1HCtB "key is already in use"
They need to be able to clone it as it is for a test.
It is the very first time that I need to give others access to a private repo. I really tried to find an explanation but I could not.
Thanks in advance

Related

Github Public Key

what is the benefit of github''public key''. I created and added it to the setting in my account. However, when I try to authenticate it in my editor, I get the error below ? Please help. I created my Repo for the heck of learning github, so maybe I still did not get the point of setting a such a key in my account. Inside of my terminal showing error message
Public key cryptography acts like a lock and key. You give Github the public key (the lock) which only you can open with your secret private key. It's a simple way for Github to authenticate you.
Your computer has to be told which private keys to use. This involves adding it to your ssh-agent which manages your private keys. See Generating a new SSH key and adding it to the ssh-agent on Github for how to do this. And read the whole Connecting to GitHub with SSH documentation.
Once this is all set up, you won't have to keep typing in your password.

Capistrano 3 deployment with multiple developers from GitHub using forward agent

I have an existing capistrano 3 deployment script which I run on my local machine (MacBook). I use agent forwarding and connect with my public SSH key. This all works fine, I have my SSH key added to GitHub and deployments works like a treat with no password. So, now I have a new developer that needs to also be able to deploy from his own machine. Firstly I have added his public SSH key to the server and added to known hosts so he has SSH access.
What do I need to do now so that agent forwarding works for him too?
I tried to copy his public key to the SSH keys in my GitHub account, but showed an error saying the key was already added. I don't understand how why I get this error as only my own SSH key has been added. Should I give him access to the GitHub repository and then he adds his SSH key to his own account?
Does the public key named in the deploy script need to be the same as it is named on the server or as it is on his machine?
Thanks for any help with this, I can't find anything online for this scenario.
Should I give him access to the GitHub repository and then he adds his SSH key to his own account?
Yes. The preferred way to do this is to give the new developer access to the GitHub project via his account.
You also add his public key to .ssh/authorized_keys on the server so that he can deploy. At this point, deployment should work for both of you using your own keys.

Cannot access a private github repo (I have both public and private keys)

I need to access (clone) a private repository on GitHub that belongs to a developer whom I am unable to communicate with. I have been provided with both a public and a private key (I'm guessing they might be deploy keys for the specific repository?)
After running the following terminal command:
git clone git#github.com:theirusername/reponame.git
I receive the following error:
Cloning into 'reponame'...
ERROR: Repository not found.
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
The developer also included the following notes in a README with the keys:
Developer notes (replaced sensitive info with 'x's)
===============
"This SSH public/private keypair allows full access to the server.
DO NOT GIVE THESE FILES TO ANYONE THAT YOU DON'T WANT ACCESSING YOUR ENTIRE SERVER AND ASSOCIATED SERVICES.
- The SSH port is XXXXX.
- There is no passphrase on the keys.
- The keys allow access to two users: `xxx` (standard privs) and `xxx` (for sudo and su-ing to root)
- These keys also allow access to the GitHub repository: github.com/theirusername/reponame.git"
I have already tried adding the public key to my Github account (under settings --> SSH and GPG keys). This did not seem to help the issue.
I'm sure there is something fundamental I'm not grasping here. Do I need BOTH the public and private keys to access the repo? If so, where do I have to register each of them? Any help would be greatly appreciated.
You need to store the public and private key in your HOME (~/.ssh)
You can then test the connection with ssh -T git#github.com: if those keys are from another developer, it should display a welcome message with the other developer name (since the public key should be registered under his/her GitHub account)
If you have multiple keys, you will need an ~/.ssh/config file, as I describe here.

Automated build from Github private repositority on Docker Hub doesn't work

I'm trying to create an automated build on Docker Hub from a Github private repository.
I linked my Github account with my Docker Hub account.
I verified that the deploy keys provided by Docker Hub are created in my Github repository
But I still have an error. I'm not sure if it's related to SSH keys or gitmodules.
Here is the log I get (in Build Details tab in my Docker Hub repo) :
Starting to clone
Cloning into 'bsntx4mjvrqncsdvzcn7tqp'...
Warning: Permanently added the RSA host key for IP address 'XXX.XX.XX.XX' to the list of known hosts.
No submodule mapping found in .gitmodules for path 'vendor/bundle/ruby/2.1.0/bundler/gems/logan-3722sdf9a9db5'
please ensure the correct public key is added to the list of trusted keys for this repository and the remote branch exists. (1)
Does anyone has the same error ?
My solution : I have solved my problem by removing the file vendor/bundle/ruby/2.1.0/bundler/gems/logan-3722sdf9a9db5 in my github repo. So the error about the public keys has nothing to do with it.
The issue is not with the key.
I don't know the exact issue. You can use the following command to sort the issue out.
git submodule update --init
The output of the command will be passed to
git rm --cached {{output}}
Push the commit.
I can't comment, so I'm posting this as an "answer" instead (sorry!)
I have the same issue with Bitbucket, it fails to fetch from my submodule which is included in my main repo. I haven't been able to fix this issue yet. I even bough a paid subscription and added an automated build in hub.docker, hoping that would fix it, but nope..
Starting to clone
Cloning into 'bokyrk3hkhspby5smhf6kby'...
Warning: Permanently added the RSA host key for IP address 'xxx.xxx.xxx' to the list of known hosts.
Submodule 'lib/shared' (https://xxx#bitbucket.org/xxx/xxx_sharedlibs.git) registered for path 'lib/shared'
Cloning into 'lib/shared'...
fatal: could not read Password for 'https://xxx#bitbucket.org': No such device or address
Clone of 'https://xxx#bitbucket.org/xxx/xxx_sharedlibs.git' into submodule path 'lib/shared' failed
please ensure the correct public key is added to the list of trusted keys for this repository and the remote branch exists. (1)
Following procedure followed by me made it work:
Added my private key to local ssh through git bash.
Added my public SSH key to github.
This ssh key was already available in my dockerhub.
So, I linked another public dockerhub userid (where automated build was successful) as a collaborator to this private automated build.
For work with private repo, you should add ssh key from Docker Hub (showing on add auto build) to your github ssh keys.
When the automated build fails the orange alert on the top of the build details can be a bit deluding:
Build failed: please ensure the correct public key is added to the
list of trusted keys for this repository and the remote branch exists.
(128)
Even when you have set up you ssh keys this message always displays. You need to look at your Logs at the bottom of the build details to see more information if you know that you have set up your ssh keys for a private repo already.
For example your logs might say:
fatal: no submodule mapping found in .gitmodules for path
'my-app/my-blog'
or maybe it could be
Dockerfile not found at ./my-app/Dockerfile
in your case you had a problem related to having the file vendor/bundle/ruby/2.1.0/bundler/gems/logan-3722sdf9a9db5 in your solution which needed to be removed.

Is an SSH Key Required to clone a public github account?

Does github require all cloning, of both public and private repositories, to use an SSH public key? Maybe a better question, is can git clone a github repo without a ssh key at all.
You can use https protocol, as mentioned in "GitHub - Https access".
You would then use your GitHub login/password in a ~/.netrc file (which can be a security concern).
Note: on Windows, that would be an _netrc file.
Since GitHub supports smart http protocol (as detailed here), you can use that for cloning/pulling and for pushing.
SSH Key is used for more safety communication. Is not necessary, although using SSH Key is usefull because encrypte communication and also does not involve password.
No. A SSH key is only needed to push to a public repo on github, not to pull from one (although the easiest method to get a clone you can later push to uses the same key to pull as to push, that isn't the only way to work).