0

I'm trying to connect to a machine with SSH and log a message to a file. Here is my example:

ssh -i .ssh/mykey ubuntu@blah.blah.blah > ~/log.txt 2> ~/err.txt

I am getting most messages written to file, just not those that require user input. For example, when connecting to a machine the first time, the following message doesn't get logged:

The authenticity of host 'blah.blah.blah (10.10.10.10)' can't be established.
RSA key fingerprint is 
a4:d9:a4:d9:a4:d9a4:d9:a4:d9a4:d9a4:d9a4:d9a4:d9a4:d9.
Are you sure you want to continue connecting (yes/no)?

I know there are options such as this

-o "StrictHostKeyChecking=no"

however, I don't want to disable this security feature. I still want the prompt. My app will look for this message, offer a (yes/no) button, and can then pipe the result to the stdin.

Any idea how I can get this message into a file for reading? And if not, why not?

  • "My app will look for this message" ... if you're developing an app, why not use a library? e.g: libssh – Attie Jul 27 '18 at 9:13
  • 1
    ssh explicitly opens /dev/tty, then writes the message and reads the response from that. So your app will have to set up a tty and interact with the ssh utility through that. There are different ways to do that, depending on how your app works. – Kenster Jul 27 '18 at 15:51
  • Perhaps I should have mentioned I'm using a node js / electron app, and trying to build an ssh client for it cross platform. The node js library's that are currently available do not prompt users at this step, instead bypassing it somehow. @Kenster that might be the missing link I was after, thank you! – Aaron Albrighton Jul 27 '18 at 23:06
0

After scratching my head for weeks, I eventually realised I could use the -v (verbose) tag with ssh and get this step to write to the stderr.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.