use ssh config defaults without hostname
Is it somehow possible to use a default ssh config without a hostname? of course I know how to use ~/.ssh/config, but I want to do something like:
Host myservers
User root
IdentitiesOnly yes
IdentityFile ~/.ssh/specialkey
ssh myservers server1.de
ssh myservers server2.de
but that wont work, so I cannot use a ssh config and define the server/hostname afterwards. That means for now I always have to do ssh -i ~/.ssh/specialkey -O IdentitiesOnly=yes [email protected] or what other possibilities would I have here to use?
Top Answer/Comment:
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.
상단 광고의 [X] 버튼을 누르면 내용이 보입니다