Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question
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". – James Sneeringer Jan 12 '12 at 22:37
heh annoying! good spot though. – SimonJGreen Jan 12 '12 at 22:41
Why not just avoid trying to connect to an invalid port? – Zoredache Jan 12 '12 at 22:43
@Zoredache This is error catching/handling. Avoiding a typo doesn't solve the problem of how to handle one gracefully ;) – SimonJGreen Jan 13 '12 at 9:50
up vote 9 down vote accepted
ssh user@localhost -q -p test 2> /dev/null 

will redirect stderr to /dev/null.

share|improve this answer
Now I feel like a complete tit. Will teach me to be coding late at night! – SimonJGreen Jan 12 '12 at 22:39

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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