Modify the snippet so it applies to the hosts in question:
Host server1.de server2.de
User root
IdentitiesOnly yes
IdentityFile ~/.ssh/specialkey
Then you just ssh server1.de
or ssh server2.de
.
You can add more entries to the Host
line. If the settings should apply to a group of servers with a common naming scheme, consider using wildcards. E.g. Host server*.de
.
Make sure you put the snippet early enough in your config (because the first obtained value for each parameter is used). Definitely before Host *
.
If you want to use some special config on demand, put the config in another file and use ssh -F
.
-F configfile
Specifies an alternative per-user configuration file. If a configuration file is given on the command line, the system-wide configuration file (/etc/ssh/ssh_config
) will be ignored. The default for the per-user configuration file is ~/.ssh/config
. […]
(source)
Example:
ssh -F ~/.ssh/myservers server1.de
Notes:
The config may contain Host *
as the only section, so it will work for any server you want.
You can create two or more configs, each in a separate file, and pick whichever you want when you connect.
An alias
alias ssh-myservers='ssh -F ~/.ssh/myservers'
will allow you to connect almost as you wanted: ssh-myservers server1.de
.
A wrapper script or a shell function can allow you to connect exactly as you wanted. Example function:
ssh() {
configfile=~/".ssh/$1"
if [ -f "$configfile" ]; then
shift; command ssh -F "$configfile" "$@"
else
command ssh "$@"
fi }
To connect with ssh myservers server1.de
you need the config to be in ~/.ssh/myservers
.
Host server1.de server2.de
?Host server*.de
?