4

I'm using ssh command to remotely executing a shell script with -o **StrictHostKeyChecking=no ** option to bypass the authentification:

ssh -o StrictHostKeyChecking=no root@$IP '/test-script'

However, I'm using a sh shell that does not support the StrictHostKeyChecking=no option:

root:~ Jeff$ ssh StrictHostKeyChecking=no root@$IP '/test-script'

Could not create directory '/home/root/.ssh'.
The authenticity of host '192.168.186.1 (192.168.186.1)' can't be established.
ECDSA key fingerprint is SHA256:KOx9T7VeRy9dJ2ug+tfnlbnG/7Fm0I5Tl/ziTkE4JaE.
Are you sure you want to continue connecting (yes/no)? 

All the -o option for ssh I have are:

ssh -o help
ssh: Available options:
ExitOnForwardFailure
UseSyslog

So is there any way I can prompt the 'yes' for the 'Are you sure you want to continue connecting (yes/no)?' question on the remote host?

I tried the following options but none of them worked

ssh -o StrictHostKeyChecking=no root@$IP '/test-script' | yes
yes | ssh StrictHostKeyChecking=no root@$IP '/test-script'
yes yes | ssh StrictHostKeyChecking=no root@$IP '/test-script'

Is there any way I can run the ssh remote command, read the prompt and find this question 'Are you sure you want to continue connecting (yes/no)?' and just enter yes?

Thank you

Olaf Dietsche
  • 72,253
  • 8
  • 102
  • 198
DavidKanes
  • 183
  • 1
  • 1
  • 10

2 Answers2

7

Assuming this is dropbear's ssh client.

From man dbclient

-y
Always accept hostkeys if they are unknown. If a hostkey mismatch occurs the connection will abort as normal.

This should be the dropbear equivalent to -o StrictHostKeyChecking=no.

Olaf Dietsche
  • 72,253
  • 8
  • 102
  • 198
  • WOW! It works great! Thank you! Did not know this spell – DavidKanes Oct 20 '20 at 16:59
  • @DavidKanes @Olaf it means if we edit in shell script to `ssh -y StrictHostKeyChecking=no` then prompt will not come at the time of debug/execute, isn't it? – Shahin P Apr 10 '23 at 11:31
  • 1
    @ShahinP No, these are two options from different ssh iplementations. `-y` belongs to dropbear, and `StrictHostKeyChecking` is from openssh. So it depends on which ssh you use. If it is openssh, use `-o StrictHostKeyChecking=no`, but if you have dropbear ssh client, you must use `-y` – Olaf Dietsche Apr 10 '23 at 11:46
  • @OlafDietsche In my script `ssh -o StrictHostKeyChecking=no` has not been mentioned but still i am getting prompt as yes/no when debug/run the shell script. – Shahin P Apr 11 '23 at 08:11
4

Try -o StrictHostKeyChecking=accept-new. From the OpenSSH documentation on StrictHostKeyChecking:

If this flag is set to accept-new then ssh will automatically add new host keys to the user's known_hosts file, but will not permit connections to hosts with changed host keys.

ssh -o StrictHostKeyChecking=accept-new root@$IP '/test-script'
Abdull
  • 26,371
  • 26
  • 130
  • 172