ConEmu, cygwin/msys and ssh-agent

When you ssh into remote computer you may use your ‘Public key’ for authentication. Private and public keys are usually stored in the user’s home directory and are often encrypted with passphrase to be more secure.

Some tools may pick up public keys automatically, some others require special switch to select key authentication mode. The example is shown below.

ssh -i $HOME/.ssh/id_rsa

To avoid typing the passphrase each time you connect any remote system you may run ssh-agent which will ‘cache’ your keys in memory for use in the current session.

By the way, if you need to run some command after logging into remote system you may append it to ssh arguments. For example you may set startup (working) directory for the remote ssh session as follows.

ssh "cd /path/to/directory ; bash --login"

How ssh-agent works

When ssh-agent starts it defines two environment variables, SSH_AGENT_PID and SSH_AUTH_SOCK, which must be exported to your shell.

On Unix systems or in cygwin ssh-agent may be started as follows:

eval $(ssh-agent)   # Create agent and environment variables

That would be nice if you are working in the single-tab console environment, but what about ConEmu and multi-tab environment?

Answer 1: Export variables

Just export these variables to the ConEmu GUI and all running consoles (Tabs and Panes).

eval $(ssh-agent)           # Create agent and environment variables
ConEmuC -export=ALL SSH_*   # Export variables to ConEmu and all its tabs

The only drawback is a limitation of the implemented export method - existing cygwin tabs will not get these variables, only new cygwin consoles will get them.

Answer 2: Modify your bash profile

GitHub documentation suggests to change your bash profile, so your ssh-agent will be initialized properly in any bash instance, regardless of the used terminal.

Also, here you may find slightly modified script, which adds ssh key files by mask.

SSH agent working with @ConEmuMaximus5 and Git Bash. For multiple tabs. Load your keys just once, use everywhere.

Using the bash script and an alias sagent.

This solution does not relates to ConEmu at first glance but may be useful anyway.