Lately I’ve been really liking using SSH Key Forwarding to let a server I’m SSH’d into authorize against my key. Most of the time it is so I can pull private git repositories on a server. The problem is when I use sudo I lose my current environment variables. Thanks to ServerFault, I found a great work-around where sudo can forward the SSH_AUTH_SOCK environment variable. You can do this by using visudo to add the following line:
Defaults env_keep+=SSH_AUTH_SOCK