0

I've generated an SSH key pair to log to my remote server. I've also added that same public key in GitHub. So from my own machine, I have SSH access to GitHub:

Hi hdodov! You've successfully authenticated, but GitHub does not provide shell access. Connection to github.com closed.

This means I can clone private repositories in my GitHub account on my local machine.


Since I use the same key to authenticate to both GitHub and my server, is it possible to use that same key to clone a repo on the server, while SSH-ed to it? If I try that, I get:

[email protected]: Permission denied (publickey).

And this makes sense, because I have no private key on the remote server - it's on my local machine. But since I've used that key connect to the server in the first place, I've proven my possession of it, so shouldn't I be able to just pull from the repo?

Yes, I can just copy my private key to the server, but transferring it over the internet sounds like a bad idea to me. Or perhaps using the same key for authentication at multiple places is the bigger issue in the first place? Should I just have separate keys?

2 Answers 2

2

What you are looking for probably is:

  1. Running ssh authentication agent (ssh-agent) on your ssh client machine;
  2. And forwarding ssh agent connection to the server (-A commandline or ForwardAgent config file option).

This way you will be able to use the keys you have locally on host on the server without physically copying them there.

1
  • That did it! Also, this article on GitHub is a good resource for setting it up. Commented Apr 6, 2020 at 13:05
0

If AddKeysToAgent is set in ssh_config (by default it's not) or if you request it in the command line, ssh itself will add the key it uses. This means if you want to use the same key to authenticate to the server and later on the server then you don't need ssh-add. You can do:

# with agent already running ssh -A -o AddKeysToAgent=yes … 
1
  • Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center. Commented Mar 12, 2024 at 9:30

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.