Search code examples
gitsshgit-pushprivate-key

Using local private key to push a repository to a git server (github) on a remote server


I have a private key that has access to my GitHub (Also I use it to connect a bunch of servers through SSH) and I use it to push/pull on my GitHub.

I have to develop code on a server with the SSH Remote option of VSCode, and it's nice to develop and run codes on the server but there is a problem. When I finished the code, I could not push my commits to GitHub because my private key was not on that server.

I develop on different servers, I do not want to share my local private key and put it on any other server.

I do not know what should I do. should I create a private key for each server? then give assign it to the corresponding repository on GitHub?

OR

Can I just use my local private key (that I am using to connect the remote servers & has access to my GitHub) just for push? it would be great if we had this option

Is there any option like this? "using your local ssh key on a remote shell without copying it on the remote server"?

When I search about this, I just get how to set up ssh on a remote server or how to set up an ssh key for GitHub. I tried searching keywords like "tunneling private key" or... It did not help.


Solution

  • You're looking for SSH Agent Forwarding. With forwarding enabled, any identities that you have loaded into your local ssh-agent will also be usable from remote servers.