I'm half way through writing a nagios script and I've hit an annoyance with SSH.

According to the man page:

-q       Quiet mode.  Causes all warning and diagnostic messages to be

Yet if I enable the quiet flag and then pass an invalid port, I still get an error:

$ ssh user@localhost -q -p test
Bad port 'test'

This is a problem, because that will make that message the first line out and that's what is grabbed by Nagios. I need to output something like "Warning|SSH error" after picking up on a != 0 exit code from ssh, but the first line I can output on is going to be line 2.

How can I make SSH TRULY quiet?

Note: I wasn't sure whether to post this question on serverfault, on superuser or on stackoverflow. I went with serverfault as the user base are probably most experienced with cli SSH and cli scripting workarounds.

  • 2
    Not that it really helps, but it looks like the manual has been updated to reflect this. As of OpenSSH 5.8 (and maybe earlier), it states that "most warnings and diagnostics" will be suppressed, instead of "all warnings and diagnostics". Jan 12 '12 at 22:37
  • heh annoying! good spot though. Jan 12 '12 at 22:41
  • Why not just avoid trying to connect to an invalid port?
    – Zoredache
    Jan 12 '12 at 22:43
  • 1
    @Zoredache This is error catching/handling. Avoiding a typo doesn't solve the problem of how to handle one gracefully ;) Jan 13 '12 at 9:50
ssh user@localhost -q -p test 2> /dev/null 

will redirect stderr to /dev/null.

  • 2
    Now I feel like a complete tit. Will teach me to be coding late at night! Jan 12 '12 at 22:39

Or, the easiest method store LogLevel QUIET in the config file:

$ cat ~/.ssh/config 
Host *
  IdentityFile ~/.ssh/id_rsa
  StrictHostKeyChecking no
  UserKnownHostsFile /dev/null
  LogLevel QUIET

Ends up getting the same result as above with lots less typing.


  • 2
    I downvoted the answer because it does not solve the issue which was asked here: % ssh -p test -oLogLevel=QUIET localhost Bad port 'test'
    – cstamas
    Oct 15 '18 at 21:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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