tmcd
tmcd

Reputation: 355

How to Clone from GitHub

I'm new using GitHub. I'm trying to clone my first file from a users repo. I keep receiving this error:

Permission denied (publickey). fatal: Could not read from remote repository

When I check to verify the public key is attached to my GitHub account, by using this command:

ssh-add -1

I get this error: The agent has no identities.

I've also tried this: ssh-add ~/.ssh/id_rsa

in which it tells me: Identity added

I also ensured that my laptop's SSH key was added to my GitHub account. What steps am I missing?

I've scanned the internet – I'm lost.

Upvotes: 12

Views: 5309

Answers (4)

Stephen Jeffrey
Stephen Jeffrey

Reputation: 21

Oh-my-zsh method:

If using oh-my-zsh you can use the ssh-agent plugin to manage you SSH connection for you.

https://github.com/robbyrussell/oh-my-zsh/tree/master/plugins/ssh-agent

  1. You'll want to edit ~/.zshrc
  2. add ssh-agent to your plugins list - plugins should be seperated by spaces not commas | e.g plugins=(git ssh-agent)
  3. Add agent-forwarding and setup your key identities, referencing your private key. These should be added above this line: source $ZSH/oh-my-zsh.sh | Reference
  4. $ source ~/.zshrc to reload your zshrc config file
  5. Confirm the identified key is available to ssh-agent $ ssh-add -l

Provided the key you identified in your ~/.zshrc file has been added to github, you will be able to connect via SSH to github.

Keychain method:

  1. ssh-add ~/.ssh/PATH_TO_YOUR_SSH_PRIVATE_KEY (e.g. ~/.ssh/id_rsa)
  2. Add the following in ~/.ssh/config - $ open ~/.ssh/config
Host * 
  AddKeysToAgent yes
  UseKeychain yes
  IdentityFile PATH_TO_YOUR_SSH_PRIVATE_KEY (e.g. ~/.ssh/id_rsa)

The AddKeysToAgent and UserKeychain params will ensure that the key is stored in keychain and made available to ssh-agent

  1. Restart your terminal

  2. Confirm the identified key is available to ssh-agent $ ssh-add -l

Provided the key you identified in your ~/.ssh/config file has been added to github, you will be able to connect via SSH to github.

Upvotes: 0

Gangaraju
Gangaraju

Reputation: 4562

You can clone a github repository in 2 ways. You can choose the type while cloning the repository.

See the highlighted part in image

  1. HTTPS

    git clone https://github.com/flyway/flyway.git

You may need to provide username/password if it is a private repository.

  1. SSH

    git clone [email protected]:flyway/flyway.git

You need to setup ssh keys in your PC and update in your github account.

Read more about

Adding SSH Keys

Which remote URL should I use?

Upvotes: 2

Shravan40
Shravan40

Reputation: 9888

Try cloning repository by https link git clone https://github.com/github_user_name/repository_name

And you can add the SSH key manually into your github account.

  1. Print your public SSH key cat ~/.ssh/id_rsa.pub
  2. Copy the output
  3. Go to your github account setting. Select SSH Keys from Personal settings.
  4. Select new SSH Key and paste the output of cat ~/.ssh/id_rsa.pub. You can give some name to remember the computer name.

Upvotes: 1

Miss J.
Miss J.

Reputation: 391

Alternatively you can use the https protocol to clone i.e https://github.com/Organization/repo.git you wouldn't need the key pair for it.

Upvotes: 0

Related Questions