2

I have below commands:

eval $(ssh-agent -s)

'[[ -f /.dockerenv ]] && echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config'

ssh-add <(echo "$PRIVATE_KEY")

Can some one explain what these commands are doing running in ubuntu linux?

2
  • Why are you running these commands? Or what's the context - what's running them?
    – Xen2050
    Commented Sep 7, 2018 at 5:42
  • the context is they are running in gitlab-runner - virtual server - for continuous integration task to build project and deploy project binary to remote server so gitlab needs to ssh to remote server to run the app on remote server
    – user61766
    Commented Sep 7, 2018 at 5:47

1 Answer 1

1

Generally speaking, and in the context of a gitlab-runner, they are running in a docker-ized version of Ubuntu to setup the ssh environment (agent, keys, and config) to make it possible for the runner to get access to the git repository.

Specifically:

eval $(ssh-agent -s)

... this starts ssh-agent and configures the environment (via eval) of the running shell to point to that agent. The agent will (below) hold the ssh keys.

'[[ -f /.dockerenv ]] && echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config'

... this (rather destructively) mucks with the ssh config file (~/.ssh/config) to tell ssh not to pay much attention to the host keys that ssh would normally use to ensure your ssh session is connecting only to validated hosts.

ssh-add <(echo "$PRIVATE_KEY")

... and finally, this adds the private ssh key to the agent (started above). The key is then going to be used to allow the runner to gain ssh access to the git remote that holds the code.

If you really want to learn more about how the runner is working, I suggest you use the manual pages to understand each command in sequence.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .