How to emulate withCredentials outside of jenkins

In a shell, I would use ssh-agent to provide the credentials for an ssh based protocol.

In a shell, I would use define the same environment variables as the withCredentials step defined for the shell steps that it is calling.