4

I understand that (almost?) all SSH command line arguments can be replaced with a property in ~/.ssh/config. But it's not at all obvious how to do this systematically: the man page for ssh only refers loosely to the config page (eg, "Port forwardings can also be specified in the configuration file."). The man page for ssh_config never refers to command line options.

So, is there a definitive list of the corresponding config parameters and command line options? For example, what does -R correspond to?

Steve Bennett
  • 5,750
  • 12
  • 47
  • 59

2 Answers2

5

Any ssh option that can be used in the form -o Option=Value can be set in the config file as an Option Value line. Many of the CLI flags are merely shorthand for long-format options, eg ssh -2 is equivalent to ssh -o Protocol=2, and can thus be set in .ssh_config as Protocol 2.

I believe that -R x:rhost:y corresponds to RemoteForward x rhost:y.

But I don't think there's any way to specify a flag that doesn't have a corresponding long-format form. And on my system the definitive list appears both in the ssh and ssh_config man pages, in the former under the -o flag, and in the latter in the main body of the page, starting very near the top.

MadHatter
  • 79,770
  • 20
  • 184
  • 232
  • Ok, so .ssh/config options can be converted to command line parameters with -o. But there isn't a way to convert short-form command line parameters, since SSH doesn't conform to GNU command line parameter conventions (eg, -R, --remote-forward). – Steve Bennett Apr 02 '13 at 07:43
  • Not quite. There is no way to convert **any** flag options - whether long or short form - to config parameters, **excepting** those that can be expressed on the CLI not only as flags but also as `-o Option=Value`. **Most** flags do have such an alternative expression; any that don't, can't be so converted. – MadHatter Apr 02 '13 at 09:22
  • Yup, cool. I guess it boils down to this: the man page should be clearer about what the alternative expression is, where there is one. – Steve Bennett Apr 02 '13 at 23:41
0

-G option will display config options. This script helps to generate a clean entry from ssh command options:

ssh2config() {
  host="$(ssh -G "$@" | sed -n 's/^hostname //p')"
  echo "$host"
  comm -23 <(ssh -G "$@" | sort) <(ssh -G abcddd | sort) | sed 's/^/    /'
  echo ''
}

Example use:

$ ssh2config -p 2222 me@there
there
    hostname there
    port 2222
    user me

I have a gist that will convert your entire ssh shell history.