0

I have production machines on Google Cloud and Amazon. On both clouds, I have common server on each called monitoring which has public ip. Through these monitoring machines, I access all machines on respective clouds. However, the problem is I have to access them like ssh -i abc.pem user@<ip address> instead I wish to access them like ssh -i abc.pem user@<machine name> How to achieve this?

2 Answers 2

0

DNS.

Easy to insert into your organization's DNS monitoring.gcp.example.net and monitoring.aws.example.net

0

@JohnMahowald's answer is the correct one if your solution has to scale to a group of people who all need convenient access to your cloud instances.

But if it's only you, and/or you can't get your DNS admin to co-operate with your request, there are other avenues you can explore.

If convenient ssh access is all you need, your ~/.ssh/config file is your friend.

$ cat << EOF >> ~/.ssh/config
Host machine_name
  Hostname ip.addr.of.machine
  User remote_username
  IdentityFile ~/.ssh/abc.pem

EOF

With that stanza in your ~/.ssh/config file, when you issue the command:

$ ssh machine_name

ssh will use the IP address given as ip.addr.of.machine and the remote username remote_username to connect to that host.

Your /etc/hosts file could also stand as a substitute for an actual DNS entry, such as if there's a web page or SNMP agent at that address that you want to query. But again, that's probably effective only if a very small number of people require convenient access.

The .ssh/config solution is highly configurable, if ssh access is all you need. And even if you do have a DNS entry for your host, you can still use a shorter, easier-to-type nickname in the Host line, and put the DNS name in the Hostname line.

Host gcp
    Hostname monitoring.gcp.example.net
    User gcp_username
    IdentityFile ~/.ssh/abc.pem

Host aws
    Hostname monitoring.aws.example.net
    User aws_username
    IdentityFile ~/.ssh/abc.pem

With those config entries you can just:

$ ssh gcp

or

$ ssh aws

to log in to either instance, using the correct username per instance, and without having to remember which identity key to use.

1
  • Thanks a lot. ~/.ssh/config solved my problem. :-)
    – innervoice
    Nov 14, 2019 at 4:48

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .