| SSH agent forwarding is great. It allows you to ssh from one server to | |
| another all the while using the ssh-agent running on your local | |
| workstation. The benefit is you don't need to generate ssh key pairs | |
| on the servers you are connecting to in order to hop around. | |
| When you ssh to a remote machine the remote machine talks to your | |
| local ssh-agent through the socket referenced by the SSH_AUTH_SOCK | |
| environment variable. | |
| So you the remote server you can do something like: | |
| > git clone git@github.com:my-github-account/my-repo.git | |
| And git will make use of the ssh-agent running on your local | |
| workstation to authenticate with github and clone your repo. | |
| This fails if you do | |
| > sudo git clone git@github.com:my-github-account/my-repo.git | |
| because your environment variables are not available to the | |
| commands running under sudo. | |
| However, you can set the SSH_AUTH_SOCK variable for the command by | |
| passing it on the command line like so | |
| > sudo SSH_AUTH_SOCK=$SSH_AUTH_SOCK git clone git@github.com:my-github-account/my-repo.git | |
| and all is well. |
This comment has been minimized.
This comment has been minimized.
elephantum
commented
Apr 13, 2014
|
Thanks, that helps a lot. |
This comment has been minimized.
This comment has been minimized.
AlekSi
commented
Jan 21, 2015
|
It's a hack, but helpful one. Thank you. |
This comment has been minimized.
This comment has been minimized.
leifmadsen
commented
Mar 17, 2015
|
Alternatively create a file in
Use |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
detailyang
commented
Nov 19, 2016
|
sudo The -E (preserve environment) is good too:) |
This comment has been minimized.
This comment has been minimized.
natemacinnes
commented
Jan 1, 2017
|
Thank you sir! |
This comment has been minimized.
This comment has been minimized.
altrofimov
commented
Jul 7, 2017
|
Had a problem to clone repository on ec2 machine, it helped. Thank you. |
This comment has been minimized.
This comment has been minimized.
mdawar
commented
Aug 7, 2017
|
A better way to preserve the
This file should be mode |
This comment has been minimized.
This comment has been minimized.
ghost
commented
Aug 1, 2018
|
Indeed, adding to sudoers Btw, OS X has |
This comment has been minimized.
This comment has been minimized.
Microserf
commented
Apr 26, 2019
|
This perfectly explained the cause of and solution to the problem I had just encountered. Thank you so much for making this helpful gist! |
This comment has been minimized.
habibalamin commentedDec 21, 2013
This has been really helpful, I was almost starting to get frustrated.