-1

I wanted to connect my multiple Linux EC2 Instances from my Ubuntu desktop, without writing the IP of each server every time I take the SSH. Just like in Windows you can use WinSCP, save the SSH key and IP's of all instances, and you can directly connect(using PuTTY) to the EC2 instances.

  • Noty sure about a UI like PuTTY but one line shell scripts named `thehostname1`, `machine2`, etc. would be very simple to put together. Then you just type `machine2` and you're off to the races. – stdunbar Aug 31 '17 at 20:50

2 Answers2

2

You can easily accomplish that in two ways. I would recommend option two. The IP addresses and hostnames used below are only examples and should be adopted by you. In both cases you can use the command as follows to connect to your EC2 instances.

ssh ec2-1
ssh ec2-2

  1. add the IP addresses and hostnames into /etc/hosts

    $cat /etc/hosts
    127.0.0.1       localhost
    10.0.0.1        ec2-1
    10.0.0.2        ec2-2
    ...
    
  2. add a configuration to SSH. On a per user basis, you can add entries in ~/.ssh/config. If that file does not exist, create it.

    Host ec2-1
        HostName 10.0.0.1
    
    Host ec2-2
        HostName 10.0.0.2
        Port 2222
        User my-ec2-user
        IdentityFile ~/.ssh/id_rsa_ec2-2
        ForwardX11 yes
    

As you can see, option two is a bit more flexible as you can configure further settings for your hosts like a non-standard SSH port, a different username or RSA key file for authentication and many more SSH options that you can find in man ssh_config.

Thomas
  • 4,155
  • 5
  • 21
  • 28
0

a simpler way is aliases (which I personally use):

alias bastion='ssh user@ip'
Mahmoud Khateeb
  • 141
  • 1
  • 1
  • 11