Author: Peeter Marvet, original idea / script from Ingmar Aasoja
Managing SSH accounts on multiple servers is made easier with ~/.ssh/config
, where
you can specify username and other options for each hostname:
Host example.com
HostName example.com
ForwardAgent yes
User virt11111
... so instead of ssh [email protected]
you can do just ssh example.com
.
Connecting to these accounts using SSHFS can be made easier using alias:
alias mount_example.com="mkdir -p ~/sshfs/example.com && sshfs -o follow_symlinks -o volname=example.com [email protected]: ~/sshfs/example.com"
But when you have A LOT of servers even managing and updating these config entries and aliases becomes a burden.
With Zone API you can generate config entries for all servers you have access to, e.g these are on your account or delegated to you (with full rights). API key can be generated in my.zone.eu self-service panel.
Download generate_ssh_configs.php and add your API credentials to array:
$zoneApiKeys = [
'zoneidusername' => 'apikeyxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
];
And run it:
php generate_ssh_configs.php
Script will generate config files ~/.ssh/[zoneidusername].config
and as an additional
feature also aliases for mounting these accounts using SSHFS in ~/[zoneidusername].alias
.
To use these add to your ~/.ssh/config
:
Include *.config
As ssh
uses first match from ~/.ssh/config
you can override generated host entries by placing
an entry before the Include
, in which case you also need to add Host *
:
Host *
Include *.config
Add to your ~/.bash_profile
if you'd like to use SSHFS:
# aliases generated from Zone API
for f in ~/*.alias; do source "$f"; done
alias umount_sshfs='for f in ~/sshfs/*; do umount "$f"; done'
# *.config files generated from Zone API
complete -W "$(echo `cat ~/.ssh/config ~/.ssh/*.config | grep -E '^Host' | cut -d" " -f2- | tr " " "\n" | grep -v "*" | sort | uniq`;)" ssh
Undocumented features:
- you can unmount all SSHFS shares with
umount_sshfs
- all hosts in config will appear as
ssh
autocomplete suggestions
- we need physical server hostname or IP in API so configs can work also when actual hostname directs elsewhere (or uses dedicated IP)
- add support for command-line arguments (what to create? for which ZoneID?)
- add support for checking / adding SSH keys and whitelisted IPs to accounts