steps to clone a private repository using Google Colab - github

I want to clone a private repository in Google Colab,
I opened a notebook on colab and did the following:
%cd "content/drive/My Drive/project"
!rm -rf /root/.ssh*
!mkdir /root/.ssh
!ssh-keygen -t rsa -b 4096 -C "githubname#github.com"
then I opened the public key by
!cat /root/.ssh/id_rsa.put
I copied the public key that is displayed after I ran the command and made a new key in my GitHub using this key.
Then I tried the following:
!ssh-keyscan GitHub.com >> /root/.ssh/known_hosts
!chmod 644 /root/.ssh/known_hosts
!chmod 600 /root/ssh/id_rsa
!ssh -T github.com
then I get the following (permission denied)
# github.com:22 SSH-2.0-babeld-d45c1532
# github.com:22 SSH-2.0-babeld-d45c1532
# github.com:22 SSH-2.0-babeld-d45c1532
Warning: Permanently added the RSA host key for IP address '140.82.113.3' to the list of known hosts.
root#github.com: Permission denied (publickey).
What do I do next?

ssh -T github.com
root#github.com: Permission denied (publickey)
That would be expected:
the right test would be:
ssh -T git#github.com
the right SSH URL to use with GitHub would be:
git#github.com:<me>/<myRepo>
You always use "git", not "root" (or your current local user) as the remote user to connect to GitHub.
Your local account remains "root" (it contains the public and private SSH key)
But connecting to GitHub means using the remote account git.

Related

Can't push to GitHub after enabling two factor auth [duplicate]

I generated an SSH key pair without a password and added the public key to GitHub.
Connection with
user#dev:/var/www/project# ssh -T git#github.com
Hi User! You've successfully authenticated, but GitHub does not provide shell access.
was successful and when I rename the key, it fails.
But when I want to push my changes, it stills ask me for my username and password combination.
Is there a way to push without a password?
If it is asking you for a username and password, your origin remote is pointing at the HTTPS URL rather than the SSH URL.
Change it to ssh.
For example, a GitHub project like Git will have an HTTPS URL:
https://github.com/<Username>/<Project>.git
And the SSH one:
git#github.com:<Username>/<Project>.git
You can do:
git remote set-url origin git#github.com:<Username>/<Project>.git
to change the URL.
In case you are indeed using the SSH URL, but still are asked for username and password when git pushing:
git remote set-url origin git#github.com:<Username>/<Project>.git
You should try troubleshooting with:
ssh -vT git#github.com
Below is a piece of sample output:
...
debug1: Trying private key: /c/Users/Yuci/.ssh/id_rsa
debug1: Trying private key: /c/Users/Yuci/.ssh/id_dsa
debug1: Trying private key: /c/Users/Yuci/.ssh/id_ecdsa
debug1: Trying private key: /c/Users/Yuci/.ssh/id_ed25519
debug1: No more authentication methods to try.
Permission denied (publickey).
I actually have already added the public key to GitHub before, and I also have the private key locally. However, my private key is of a different name called /c/Users/Yuci/.ssh/github_rsa.
According to the sample output, Git is trying /c/Users/Yuci/.ssh/id_rsa, which I don't have. Therefore, I could simply copy github_rsa to id_rsa in the same directory.
cp /c/Users/Yuci/.ssh/github_rsa /c/Users/Yuci/.ssh/id_rsa
Now when I run ssh -vT git#github.com again, I have:
...
debug1: Trying private key: /c/Users/Yuci/.ssh/id_rsa
debug1: Authentication succeeded (publickey).
...
Hi <my username>! You've successfully authenticated, but GitHub does not provide shell access.
...
And now I can push to GitHub without being asked for username and password :-)
As usual, create an SSH key and paste the public key to GitHub. Add the private key to ssh-agent. (I assume this is what you have done.)
To check everything is correct, use ssh -T git#github.com
Next, don't forget to modify the remote point as follows:
git remote set-url origin git#github.com:username/your-repository.git
Additionally for gists, it seems you must leave out the username
git remote set-url origin git#gist.github.com:<Project code>
You have to use the SSH version, not HTTPS. When you clone from a repository, copy the link with the SSH version, because SSH is easy to use and solves all problems with access. You can set the access for every SSH you input into your account (like push, pull, clone, etc...)
Here is a link, which says why we need SSH and how to use it: step by step
Git Generate SSH Keys
for using SSH you must use $ git remote add origin git#github.com:USERNAME/REPOSITORY.git instead of git remote add origin remote_repository_URL.
you can check it with $ git remote -v, if you see 2 lines in the below format, it will work correctly:
origin git#github.com:username/repo-name.git (fetch)
origin git#github.com:username/repo-name.git (push)
Like the other users mentioned, you must convert it from using HTTPS to SSH. I don't see an answer with an end-to-end solution. After setting up the ssh keys, do (on your local machine) :
$ git remote set-url origin git#github.com:username/your_repo.git # Convert HTTPS -> SSH
$ ssh-add ~/.ssh/id_rsa_github # add private github ssh key ssh-agent (assuming you have it already running)
$ git push
You did everything ok but git still asking by password, this worked for me, execute the next commando in your current project's path:
~ ssh-add -K ~/.ssh/id_rsaYourIdRsa
Add your SSH private key to the ssh-agent and store your passphrase in the keychain. If you created your key with a different name, or if you are adding an existing key that has a different name, replace id_rsaYourIdRsa in the command with the name of your private key file.
Using the command line:
Enter ls -al ~/.ssh to see if existing SSH keys are present.
In the terminal is shows: No directory exist
Then generate a new SSH key
Step 1.
ssh-keygen -t rsa -b 4096 -C "your_email#example.com"
step 2.
Enter a file in which to save the key (/Users/you/.ssh/id_rsa): <here is file name and enter the key>
step 3.
Enter passphrase (empty for no passphrase): [Type a password]
Enter same passphrase again: [Type password again]

ssh -T github.com results in ssh could not resolve hostname github

I am trying to clone my public Git repository using Putty instead of Git Bash. I am doing this over ssh instead of Https(which is the requirement). The Linux machine which i am accessing through putty has IBM OS(Linux on z/os). I have created the rsa keys and added same on Github. While trying to clone my repository , i am getting error as
'ssh-rsa: /usr/lpp/Files/.ssh/id_rsa.pub 1: FSUM7351 not found
fatal: Could not read from remote repository.' although the public key is present.
IBMUSER:/Z21S/usr/lpp/Files/.ssh: >ls
id_rsa id_rsa.pub
When i am trying to issue command ssh -T github.com, i am getting error as ssh could not resolve hostname github
Please suggest.

SSH Agent Forwarding not working

I'm having an hard time trying to configure Capistrano 3.1 to deploy an app hosted on Github.
I'm following Capistrano Documentation and I have successfully completed the first step (SSH keys from workstation to servers) and on the second one (From our servers to the repository host) I'm able to successfully run ssh -A deploy#one-of-my-servers.com 'git ls-remote git#github.com:my_user/my_repo.git':
18f38afz261df35d462f7f4e2ca847d22f148a06 HEAD
18f38afz261df35d462f7f4e2ca847d22f148a06 refs/heads/master
however, ssh deploy#one-of-my-servers.com 'git ls-remote git#github.com:my_user/my_repo.git' fails:
Permission denied (publickey).
Capistrano docs suggests
If you get the error "host key verification failed." log in into your server and run as the deploy user the command ssh git#github.com to add github.com to the list of known hosts.
SO, I tried so but I get
ssh git#github.com
Warning: Permanently added the RSA host key for IP address '192.30.252.131' to the list of known hosts.
Permission denied (publickey).
And I'm basically not able to successfully access the Github repo.
SSH documentation states:
-A Enables forwarding of the authentication agent connection. This
can also be specified on a per-host basis in a configuration
file.
How can I specified on a per-host basis in a configuration file?
My local machine runs Mac OSX Mavericks.
The VPS runs Ubuntu 12.04
Thanks.
Do you have your ssh key added to the list of agent identites ?
You can check with ssh-add -L , you should see the key your are using to connect to github :
$ ssh-add -L
ssh-rsa AAAAB3N.....0VmSiRvTzBrbU0ww== /Users/youruser/.ssh/id_rsa
If you don't see the ssh key you use for github or a message like
The agent has no identities.
Then you should add your key with :
ssh-add ~/.ssh/id_rsa
(replace with the path to the key you use for github)
See the ssh-add doc for more info
Add following lines to .ssh/config file on your local computer
Host Server_Address
ForwardAgent yes
Check your local key whether listed in ssh-add list or not with
ssh-add -L
If not add key to SSH Agent
ssh-add -K
Connect to Remote Server
ssh -v username#Server_Address
Check SSH Agent forwarding is enabled by running following command. It should list a socket file
echo "$SSH_AUTH_SOCK"
Run connection test against GitHub
ssh -T git#github.com
Run ls remote test against targeted git repository
git ls-remote --heads git#github.com:account/repo.git
Finally logout and run following from your local machine
cap production git:check
Add the following to ~/.ssh/config
Host one-of-my-servers.com
ForwardAgent yes
Yet another cause: If the target host's fingerprint doesn't match with your ~/.ssh/known_hosts, SSH automatically disables Agent Forwarding.
The solution is:
$ ssh -A -o UserKnownHostsFile=/dev/null my-target-host

Push to GitHub without a password using ssh-key

I generated an SSH key pair without a password and added the public key to GitHub.
Connection with
user#dev:/var/www/project# ssh -T git#github.com
Hi User! You've successfully authenticated, but GitHub does not provide shell access.
was successful and when I rename the key, it fails.
But when I want to push my changes, it stills ask me for my username and password combination.
Is there a way to push without a password?
If it is asking you for a username and password, your origin remote is pointing at the HTTPS URL rather than the SSH URL.
Change it to ssh.
For example, a GitHub project like Git will have an HTTPS URL:
https://github.com/<Username>/<Project>.git
And the SSH one:
git#github.com:<Username>/<Project>.git
You can do:
git remote set-url origin git#github.com:<Username>/<Project>.git
to change the URL.
In case you are indeed using the SSH URL, but still are asked for username and password when git pushing:
git remote set-url origin git#github.com:<Username>/<Project>.git
You should try troubleshooting with:
ssh -vT git#github.com
Below is a piece of sample output:
...
debug1: Trying private key: /c/Users/Yuci/.ssh/id_rsa
debug1: Trying private key: /c/Users/Yuci/.ssh/id_dsa
debug1: Trying private key: /c/Users/Yuci/.ssh/id_ecdsa
debug1: Trying private key: /c/Users/Yuci/.ssh/id_ed25519
debug1: No more authentication methods to try.
Permission denied (publickey).
I actually have already added the public key to GitHub before, and I also have the private key locally. However, my private key is of a different name called /c/Users/Yuci/.ssh/github_rsa.
According to the sample output, Git is trying /c/Users/Yuci/.ssh/id_rsa, which I don't have. Therefore, I could simply copy github_rsa to id_rsa in the same directory.
cp /c/Users/Yuci/.ssh/github_rsa /c/Users/Yuci/.ssh/id_rsa
Now when I run ssh -vT git#github.com again, I have:
...
debug1: Trying private key: /c/Users/Yuci/.ssh/id_rsa
debug1: Authentication succeeded (publickey).
...
Hi <my username>! You've successfully authenticated, but GitHub does not provide shell access.
...
And now I can push to GitHub without being asked for username and password :-)
As usual, create an SSH key and paste the public key to GitHub. Add the private key to ssh-agent. (I assume this is what you have done.)
To check everything is correct, use ssh -T git#github.com
Next, don't forget to modify the remote point as follows:
git remote set-url origin git#github.com:username/your-repository.git
Additionally for gists, it seems you must leave out the username
git remote set-url origin git#gist.github.com:<Project code>
You have to use the SSH version, not HTTPS. When you clone from a repository, copy the link with the SSH version, because SSH is easy to use and solves all problems with access. You can set the access for every SSH you input into your account (like push, pull, clone, etc...)
Here is a link, which says why we need SSH and how to use it: step by step
Git Generate SSH Keys
for using SSH you must use $ git remote add origin git#github.com:USERNAME/REPOSITORY.git instead of git remote add origin remote_repository_URL.
you can check it with $ git remote -v, if you see 2 lines in the below format, it will work correctly:
origin git#github.com:username/repo-name.git (fetch)
origin git#github.com:username/repo-name.git (push)
Like the other users mentioned, you must convert it from using HTTPS to SSH. I don't see an answer with an end-to-end solution. After setting up the ssh keys, do (on your local machine) :
$ git remote set-url origin git#github.com:username/your_repo.git # Convert HTTPS -> SSH
$ ssh-add ~/.ssh/id_rsa_github # add private github ssh key ssh-agent (assuming you have it already running)
$ git push
You did everything ok but git still asking by password, this worked for me, execute the next commando in your current project's path:
~ ssh-add -K ~/.ssh/id_rsaYourIdRsa
Add your SSH private key to the ssh-agent and store your passphrase in the keychain. If you created your key with a different name, or if you are adding an existing key that has a different name, replace id_rsaYourIdRsa in the command with the name of your private key file.
Using the command line:
Enter ls -al ~/.ssh to see if existing SSH keys are present.
In the terminal is shows: No directory exist
Then generate a new SSH key
Step 1.
ssh-keygen -t rsa -b 4096 -C "your_email#example.com"
step 2.
Enter a file in which to save the key (/Users/you/.ssh/id_rsa): <here is file name and enter the key>
step 3.
Enter passphrase (empty for no passphrase): [Type a password]
Enter same passphrase again: [Type password again]

How to set up authentication for two separate GitHub accounts from same ssh client?

The short version:
Is there any way to set up automatic public-key-based ssh authentication from one Linux account to two different Github accounts?
I have two Github accounts, a work one and a personal one, which I want to keep entirely separate.
I already set up automatic ssh authentication (using my ~/.ssh/id_rsa.pub) in my work Github account. It works fine.
When I try to add the same ssh key to my personal Github account, I get the error that the "key is already in use."
EDIT: OK, I guess that one may be able to do what I want to do through suitable settings in ~/.ssh/config, but I have not yet figured out what these should be. For one thing, it's not clear to me how to specify two different authentication details (User, IdentityFile) for the same host (github.com), and once I do, I don't see how git knows which of the two keys to present when I do git push.
You need to create two sets of (public/private) keys, one for each account.
You can reference them through an ssh config file, as detailed in "GitHub: Multiple account setup"/
#Account one
Host github.com
HostName github.com
PreferredAuthentications publickey
IdentityFile /c/Users/yourname/.ssh/id_rsa
User git
#Account two
Host ac2.github.com
HostName github.com
PreferredAuthentications publickey
IdentityFile /c/Users/yourname/.ssh/id_rsa_ac2
User git
It seems GitHub doesn't allow the same RSA key for two repositories.
As workaround, you've to create separate RSA keys for each site:
ssh-keygen -t rsa -f rsa_site1
ssh-keygen -t rsa -f rsa_site2
This will generate private and public keys. Then add public keys into GitHub to Deploy keys.
Then deploy your private keys into the remote:
cat rsa_site1 | ssh user#remote "cat > ~/.ssh/rsa_site1 && chmod 600 ~/.ssh/rsa_site1"
cat rsa_site2 | ssh user#remote "cat > ~/.ssh/rsa_site2 && chmod 600 ~/.ssh/rsa_site2"
And to fetch your private repository on the server, you can use something like:
ssh user#remote 'ssh-agent sh -c '\''cd /webroot/site1 && ssh-add ~/.ssh/rsa_site1 && git fetch git#github.com:priv/site1.git'\'
ssh user#remote 'ssh-agent sh -c '\''cd /webroot/site2 && ssh-add ~/.ssh/rsa_site2 && git fetch git#github.com:priv/site2.git'\'