10

For Ruby, using 2 spaces is the best. For Python, using 4 spaces is the best.

But for ssh config file, how many spaces is the best?

2
  • 1
    Are you considering tabs too? :) - I use 4 spaces...
    – urban
    Nov 14, 2017 at 9:22
  • 3
    michaelheap.com/ssh-config-files "Indentation isn't significant"
    – user7191279
    Nov 14, 2017 at 9:23

2 Answers 2

16

I found the originally accepted answer a bit confusing so I thought I'd contribute some additional information.

To the original question, ssh config files allow, but do not require, indentation with whitespace (either tabs or spaces). Blank lines and lines beginning with a hash # are ignored.

The config file consists of stanzas, each beginning with the reserved word Host or Match followed by a list of options until the stanza ends at the next Host, Match or end of file.

The options can be specified as name value or name=value. Looking at the OpenSSH release notes, it appears the developers use the name=value format. Leading whitespace is ignored. Unquoted in-line whitespace is also ignored

The following (mixing with and without equals and whitespace) are equivalent

Host test1
Hostname = 192.168.0.100

Host test1
    Hostname 192.168.0.100

    Host=test1
    Hostname 192.168.0.100

Note that the equal sign is significant when parsing options. Values with embedded equals signs need to be quoted. This contrived example demonstrates what happens without quotes.

Host test1
    Hostname = 192.168.0.100
    UserKnownHostsFile /tmp/name_with=equals /tmp/name2

Will look for known host in /tmp/name_with and in /tmp/name2 but not in /tmp/name_with=equals.

1
7

The configuration files (for ssh or other programs) do not need indentation.

They contain lines of type name=value.
Some programs allow spaces around the equal sign, others are more strict and do not accept them.

ssh accepts spaces around the equal sign but they are ignored. Use how many of them you like but don't abuse them and let the file be readable.

A small fragment from the documentation:

The file contains keyword-argument pairs, one per line. Lines starting with # and empty lines are interpreted as comments. Arguments may optionally be enclosed in double quotes (") in order to represent arguments containing spaces. Configuration options may be separated by whitespace or optional whitespace and exactly one =; the latter format is useful to avoid the need to quote whitespace when specifying configuration options using the ssh, scp, and sftp -o option.

1
  • 3
    um definitely not all lines in .ssh/config are name=value Jun 5, 2019 at 22:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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