Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How many white spaces is the best for ssh config

Tags:

ssh

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?

like image 846
shirakia Avatar asked Nov 14 '17 09:11

shirakia


2 Answers

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.

like image 24
axiac Avatar answered Sep 24 '22 03:09

axiac


I found the above 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.

like image 194
user2070305 Avatar answered Sep 24 '22 03:09

user2070305