SSH Key Forwarding & Sudo

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.

Posted by Justin Carmony on February 24th, 2014

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:


[code]

Defaults env_keep+=SSH_AUTH_SOCK

[/code]

About Justin Carmony

Justin is the Director of Engineering for Deseret Digital Media, President of the Utah PHP Usergroup, and member of the Utah Open Source Foundation which organizes the OpenWest Conference. Justin loves just about anything with web technologies from PHP, JavaScript, Node.js, Salt, and managing engineering teams.

Learn More