I've tried researching my options, but, nothing works quite the way I need it to. Most helpful information is found here: scp files via intermediate host
I have the following setup: I'm on Machine A. I have keys set up on Machine B (with ssh agent enabled) that grant me access to Machine C. (As an aside, the reason for this configuration is that access to machine B is heavily restricted, including two factor authentication, and every other machine is configured to only allow SSH root access coming from this machine.)
The issue is that the ssh-agent code only runs for login shells, not when commands are run over ssh, so it doesn't attempt to use the key that is located on Machine B to access Machine C. This is the code in my .bashrc and .profile:
export SSH_AUTH_SOCK=~/.ssh/ssh-agent.$HOSTNAME.sock
ssh-add -l 2>/dev/null >/dev/null
if [ $? -ge 2 ]; then
ssh-agent -a "$SSH_AUTH_SOCK" >/dev/null
fi
Ideally, I'd like to be able to alias some command so that I can run it just like scp (e.g. scpproxy localfile user@MachineC:/root/remotefile). My current solution is, from Machine B, scp -3 user@MachineA:localfile user@MachineC:remotefile (where the -3 causes scp to use the local machine as an intermediate host, instead of the default where it tries to copy directly from A to C) which is less than perfect.
Any help is appreciated!