SSH from one EC2 instance to another EC2

-2

I am working on a test project that has EC2 instance (Controller) SSH to other EC2 instances (nodes).

I would like to SSH to be able to login as EC2-user@xxx.xxx.xxx.xxx to the nodes, from the controller instance, so additional user accounts do not need to be provisioned on the node instances.

My ultimate goal is to use keys so Controller can SSH over to the Nodes.

How would you suggest I solve for this?

LaR

Posted 2018-02-10T03:55:29.583

Reputation: 1

Answers

0

I think you can use public and private keys to make it work.

I might be wrong but regardless of what accounts exists on your instances in my head this works:

​Make keypair on the controller:

ssh-keygen -t rsa -f controller.rsa

Copy public key from controller to nodes:

ssh-copy-id -i controller.rsa.pub node-account@node-x.example.com

Setup config file on controller:

vim ~/.ssh/config

~/.ssh/.config file contents:

Host node-a.example.com
User node-a-account
IdentityFile ~/.ssh/controller.rsa

Host node-b.example.com
User node-b-account
IdentityFile ~/.ssh/controller.rsa

Host node-c.example.com
User node-c-account
IdentityFile ~/.ssh/controller.rsa

Now your controller can ssh into any node like so: ssh node-x

Louis

Posted 2018-02-10T03:55:29.583

Reputation: 18 859