I am working on recon for a set of systems my company is taking over and they use a different authentication method than we do. Specifically we use AD auth and a jump server to access systems where they use a mix of Keys, passphrases and others for various systems.
For systems that use an SSH key I am trying to write a script that allows me to automate a login and run a command to retrieve data. My key has a password on it and thus I am trying to leverage ssh-agent to allow my script the ability to authenticate to the systems with little to no input.
So far it seems the issue is when I run something like the following, ssh-agent either A.) Dies and ends before my for loop, or B.) prints the commands for environment variables and doesn't pull them into the scope.
eval ssh-agent
ssh-add ~/.ssh/${USER}_mvc
for i in `cat ${HOSTLIST}`
do
ssh -l ${USER} ${i} -t 'uname -r'
&>${OUTDIR}/${i}.keyauthcollector
done
I know I'm missing something to pull in the variables SSH Agent generates but I can't seem to find it and of course all the scripts I find when searching google for SSH-Agent scripting help are looking to make ssh-agent run for your current session not a script.