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:
Include: added in OpenSSH 7.3.PubkeyAcceptedAlgorithms: the name since OpenSSH 8.5. Older clients know onlyPubkeyAcceptedKeyTypes, which newer ones still accept.WarnWeakCrypto: added in OpenSSH 10.1, to control the post-quantum warning. See SSH "connection is not using a post-quantum key exchange algorithm".
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
IgnoreUnknownline, separated by commas. As with most options, only the firstIgnoreUnknownvalue is used, so a second line is ignored. - An
IgnoreUnknowninsideHost github.comapplies 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. IgnoreUnknownitself 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 asUseRoaming, are skipped without a message.line 2: invalid time value.orBad 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.
Related
- The ssh config file
- SSH "Bad owner or permissions on ~/.ssh/config": what it checks and how to fix it
- SSH "connection is not using a post-quantum key exchange algorithm"
- Do scp and sftp use ~/.ssh/config? Host aliases, -F and -P
- SSH error messages, what each one means
- sshd_config.d drop-in ignored: the first value wins (KexAlgorithms and others)
Sources
- ssh_config(5): IgnoreUnknown and the client keywords
- sshd_config(5): the server keywords
- sshd(8): -t test mode
- OpenSSH source, readconf.c: the keyword table and these messages
- Technical Note TN2449: OpenSSH updates in macOS 10.12.2, UseKeychain and IgnoreUnknown
- OpenSSH 6.3 release notes: IgnoreUnknown
- OpenSSH 7.3 release notes: Include
- OpenSSH 8.5 release notes: PubkeyAcceptedAlgorithms
- OpenSSH 10.1 release notes: WarnWeakCrypto