Disable "Permanently added <host> ..." warning on local LAN
I have the following in my ssh_config
to connect to machines on my local LAN and machines in a VM:
Host 172.16.*.*
StrictHostKeyChecking no
UserKnownHostsFile /dev/null
However, each time I connect it produces a warning:
$ ssh [email protected]
Warning: Permanently added '172.16.4.11' (ECDSA) to the list of known hosts.
Enter passphrase for key '/Users/jdoe/.ssh/id_ed25519':
I'm using OpenSSH 7.1. How do I disable the warning on each connection for the local LAN?
Solution 1:
Append the following to your SSH config file:
LogLevel ERROR
Or append -o LogLevel=ERROR
to the ssh command itself.
Solution 2:
You should be able to do this by changing your ssh configuration from the default log-level of "info" to "error" (the next level up).
Refer to the ssh_config
manual page:
LogLevel
Gives the verbosity level that is used when logging messages from ssh(1). The possible values are:QUIET
,FATAL
,ERROR
,INFO
,VERBOSE
,DEBUG
,DEBUG1
,DEBUG2
, andDEBUG3
. The default isINFO
.DEBUG
andDEBUG1
are equivalent.DEBUG2
andDEBUG3
each specify higher levels of verbose output.
The source code for ssh
tells the story:
/*
* Initialize "log" output. Since we are the client all output
* actually goes to stderr.
*/
log_init(av[0], options.log_level == -1 ? SYSLOG_LEVEL_INFO : options.log_level,
SYSLOG_FACILITY_USER, 1);
along with the definition of log_init
:
void
log_init(char *av0, LogLevel level, SyslogFacility facility, int on_stderr)
{
i.e., all of the "log" messages go to the standard error, and you can only adjust how many you get. The one you do not want happens to be at the INFO
level.
Solution 3:
In short, run ssh with the -q flag to disable warnings/diagnostics (but not errors).
Solution 4:
Most answers here are not that perfect, where you will lose other important warning or error messages. To only suppress that warning message 'Permanently added ...'
and keep other warning messages, you could do the following:
Using error redirection and grep -v
The warning message that you've seen on the terminal is a standard error
. So, we need convert the standard error output to standard output and finally using grep -v
to remove that annoying warning string:
ssh [email protected] 2> >(grep -v "Permanently added" 1>&2)
Even you could suppress the warning for only that specific IP:
ssh [email protected] 2> >(grep -v "Permanently added '[172.16.4.11]'" 1>&2)
If you need to suppress more than one warning messages use grep -Ev
and separate the warning messages with |
:
ssh [email protected] 2> >(grep -v grep -Ev "Permanently added|Warning message 1|Other error message 2|Other error or warning N" 1>&2)
This way, you still able to view other important warning or error messages.