Mario Ruiz
Mario Ruiz

Reputation: 72

How to supply keys when calling a bash in ruby

Using Ruby I am trying to get the content from a file that is on another machine by doing:

run_this = `ssh user@thecomputer cat myfile.txt`

The problem is the first time this is run, it is waiting for introducing 'yes' or 'no':

The authenticity of host 'thecomputer (11.12.134.46)' can't be established. ECDSA key fingerprint is SHA256:xxxxxxxxxxxxxxxxxxxxxxxxx. Are you sure you want to continue connecting (yes/no)?

I need to supply the 'yes' automatically without manual intervention

How can I do it?

Upvotes: 0

Views: 50

Answers (1)

Mark
Mark

Reputation: 4453

run_this = `ssh -oStrictHostKeyChecking=no user@thecomputer cat myfile.txt`

Without the StrictHostKeyChecking option turned off, ssh typically defaults to not trusting any new hosts and will interactively prompt the user if there is one, otherwise it will fail.

The problem you are having is very common. For example, here's someone who was trying to get around this ssh behavior with rsync:

Bypass Rsync Prompt "Are you sure you want to continue connecting"

Upvotes: 1

Related Questions