I have a remote CentOS server, lets pretend it's called hostname.com
hostname.com has several user accounts, and I want to ssh into this server as any one of these users (using ssh keys rather than password).
It seems everyone recommends just changing my local ssh config, add an alias the server for each remote user, and then providing a different IdentityFile for each alias.
So then I have to ssh bob@aliased_hostname1
and ssh alice@aliased_hostname2
Are there any other solutions? Id rather not be ssh'ing into aliased hostnames
Ideally I want to just ssh [email protected]
or ssh [email protected]
and automatically choose the correct ssh keyfile, based on the remote username i'm trying to log in as.
Check out the
Match
keyword in your SSH config on the client machine. Specifically, theuser
andhost
criteria. Thessh_config(5)
man page states (emphasis mine):So in your case you'd be looking at something like:
There's one SuperUser and one Unix & Linux Q/A that helped tie it all together, so you should probably go upvote those participants as well.