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.

  • 3
    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, 2012 at 22:37
  • heh annoying! good spot though. Jan 12, 2012 at 22:41
  • 1
    Why not just avoid trying to connect to an invalid port?
    – Zoredache
    Jan 12, 2012 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, 2012 at 9:50

2 Answers 2

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, 2012 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, 2018 at 21:36
  • The "issue" in the original post is -p test. test is not a valid port so ssh cannot possibly succeed when called with -p test. It makes no sense to suppress a real error, instead of just fixing it (or deleting the call to ssh in the first place since it does nothing useful except printing the error). This answer is in general the best in answering "how to quiet ssh warnings" (as opposed to real errors). It is in fact how I got here, and it helped me the most. Down-voting because it doesn't solve the specific issue OP had, seems to be a bit harsh.
    – arielf
    Apr 20, 2022 at 0:49
  • just add a -p and a port number - it still works, quietly :-)
    – todd_dsm
    Apr 21, 2022 at 3:43
  • Came here looking for exactly what @todd_dsm posted, thank you. In my case, I wanted LogLevel ERROR, to avoid seeing Warning: Permanently added '' (RSA) to the list of known hosts. when connecting to an embbeded device that I'm reflashing multiple times per day at work (hence causing its server key to be regenerated). I'd already added UserKnownHostsFile /dev/null and StrictHostKeyChecking no, so this was the last piece of the puzzle for me. Upvoted.
    – evadeflow
    Mar 20 at 18:34

You must log in to answer this question.

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