Recently I've installed latest openssh (7.5p1) to mess around with the config. As i'm having lots of hosts decided to use Include to make things more clear. Here is a basic file structure:
~/.ssh/
├── config
└── config.d
├── crp
│ ├── prod
│ ├── puppet
│ ├── qa
│ └── test
└── priv
├── default
├── github
├── gitlab
└── home
~/.ssh/config
## PERSONAL
Include ~/.ssh/config.d/priv/default
Include ~/.ssh/config.d/priv/home
## GITHUB
Include ~/.ssh/config.d/priv/github
## GITLAB
Include ~/.ssh/config.d/priv/gitlab
## CORPORATE
## TEST
Include ~/.ssh/config.d/crp/test
## QA
Include ~/.ssh/config.d/crp/qa
## PROD
Include ~/.ssh/config.d/crp/prod
## Puppet env
Include ~/.ssh/config.d/crp/puppet
Host *
ControlMaster auto
ControlPath ~/.ssh/socket-%r@%h-%p
ControlPersist 600
ForwardX11 no
ForwardX11Trusted yes
Protocol 2
ServerAliveInterval 60
ServerAliveCountMax 30
~/.ssh/config.d/priv/default
Host server1
hostname 111.111.111.111
user natur
Host server2
forwardagent yes
hostname 222.222.222.222
user natur
~/.ssh/config.d/priv/github
Host github.com
HostName github.com
User git
IdentitiesOnly yes
IdentityFile ~/.ssh/identities/priv/id_rsa
~/.ssh/config.d/crp/test
Host test-relay-server
hostname 111.111.111.111
ForwardAgent yes
tcpkeepalive yes
Host test-*
user natur
serveraliveinterval 60
proxycommand ssh -q -W %h:%p test-relay-server
Host test-proxy
hostname 10.10.10.10
~/.bashrc
_ssh()
{
local cur prev opts
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
opts=$(grep -R '^Host' ~/.ssh/config.d/ | grep -v '[?*]' | cut -d ' ' -f 2-)
COMPREPLY=( $(compgen -W "$opts" -- ${cur}) )
return 0
}
complete -F _ssh ssh
Sample ssh connection debug
+ exec /usr/bin/ssh -A server1 -v
OpenSSH_7.5p1 Ubuntu-5ubuntu1, OpenSSL 1.0.2g 1 Mar 2016
debug1: Reading configuration data /home/natur/.ssh/config
debug1: Reading configuration data /home/natur/.ssh/config.d/priv/default
debug1: /home/natur/.ssh/config.d/priv/default line 1: Applying options for server1
debug1: Reading configuration data /home/natur/.ssh/config.d/priv/home
debug1: Reading configuration data /home/natur/.ssh/config.d/priv/github
debug1: Reading configuration data /home/natur/.ssh/config.d/priv/gitlab
debug1: Reading configuration data /home/natur/.ssh/config.d/crp/test
debug1: Reading configuration data /home/natur/.ssh/config.d/crp/qa
debug1: Reading configuration data /home/natur/.ssh/config.d/crp/prod
debug1: Reading configuration data /home/natur/.ssh/config.d/crp/puppet
debug1: /home/natur/.ssh/config line 27: Applying options for *
...