Strovent SystemsSign in
Reference

SSH "Bad configuration option" in ~/.ssh/config or sshd_config

ssh stops with "line N: Bad configuration option" when it does not know a keyword: a typo, a newer or macOS-only option, a server option, or a stray key.

OpenSSH reads its configuration file before it connects. If a line starts with a keyword it does not know, it names the file, the line and the keyword, and stops. ssh prints the keyword in lowercase:

/home/user1/.ssh/config: line 14: Bad configuration option: usekeychain
/home/user1/.ssh/config: terminating, 1 bad configuration options

Nothing was sent to the server. Go to the line number shown and use the keyword to find which case below applies. Every bad line is listed before ssh stops, and the count on the last line is how many there are. The check runs on every line of the file, including lines inside a Host block that does not match the host you are connecting to.

A typo

A common one is IdentifyFile for IdentityFile. Case does not matter, so hostname and HostName are the same keyword. Compare the line with the keyword list in the ssh_config manual.

A key or other text pasted into the file

/home/user1/.ssh/config: line 1: Bad configuration option: ssh-ed25519

The first word of a public key line (ssh-ed25519, ssh-rsa) became the keyword. A public key belongs in ~/.ssh/authorized_keys on the server, not in config. To point ssh at a key, use IdentityFile ~/.ssh/id_ed25519.

If the message shows garbage such as \377\376h as the keyword, here or in no argument after keyword, the file was saved as UTF-16, which some Windows editors do. A keyword that starts with \357\273\277, such as \357\273\277host, means a UTF-8 byte order mark at the start of the file. Save it as plain UTF-8 (or ASCII) without a byte order mark.

An option your ssh version does not have

Options are added over time, so a config file copied from a newer system can fail on an older client. Some that often appear in this error:

Run ssh -V to see which version is reading the file. On a computer with more than one ssh installed, the one found first on your PATH may not be the one you expect.

UseKeychain, a macOS-only option

UseKeychain is an option that exists only in the ssh shipped with macOS, where it stores key passphrases in the Mac keychain. Upstream OpenSSH, as used on Linux and in Windows OpenSSH, does not have it, so a config file copied from a Mac fails there with Bad configuration option: usekeychain.

Keep one file for every system: IgnoreUnknown

IgnoreUnknown tells ssh to skip the named keywords if it does not know them. It must come before the first line that uses them, so put it at the top of the file, outside any Host block:

IgnoreUnknown UseKeychain,WarnWeakCrypto

Host *
  AddKeysToAgent yes
  UseKeychain yes
  • List every keyword on one IgnoreUnknown line, separated by commas. As with most options, only the first IgnoreUnknown value is used, so a second line is ignored.
  • An IgnoreUnknown inside Host github.com applies only while that block matches. Lines that use the option elsewhere still fail.
  • A system that does know the keyword uses it normally.
  • On the command line: ssh -o IgnoreUnknown=UseKeychain -o UseKeychain=yes host.example.com.
  • IgnoreUnknown itself was added in OpenSSH 6.3.

A server option in the client file, or the reverse

ssh_config (client) and sshd_config (server) have different keywords. ClientAliveInterval, Subsystem, AcceptEnv and PermitRootLogin belong in /etc/ssh/sshd_config. StrictHostKeyChecking, ServerAliveInterval and IdentityFile belong in ~/.ssh/config or /etc/ssh/ssh_config. Putting one in the other file gives this error.

The server prints the same form, for example /etc/ssh/sshd_config: line 43: Bad configuration option: StrictHostKeyChecking. Test the server file before you restart the service, so a bad line does not stop sshd from starting:

sudo sshd -t

It prints nothing when the file is valid.

Messages that look similar

  • line 2: no argument after keyword "usekeychain": the keyword is there but has no value after it.
  • line 2: Unsupported option "rsaauthentication": an option that was removed from OpenSSH. It is a warning and ssh carries on; delete the line. Other removed options, such as UseRoaming, are skipped without a message.
  • line 2: invalid time value. or Bad SSH2 cipher spec: the keyword is fine but its value is not.
  • "Bad owner or permissions on ~/.ssh/config": the file's contents are fine, its permissions are not. See SSH "Bad owner or permissions on ~/.ssh/config": what it checks and how to fix it.

To see the settings ssh will use once the file parses, run ssh -G host.example.com.

Sources

Spotted a mistake? Email [email protected].