SSH into AWS Cloud9 Environment
Asked Answered
M

2

11

I would like to SSH into my Amazon Web Services (AWS) Cloud9 Elastic Cloud Compute (EC2) environment, but there is no key pair assigned to the Cloud9 EC2 environment. How can I assign a key pair to that environment, so that I can SSH into it?

I created the AWS Cloud9 EC2 environment through the Cloud9 interface, rather than creating the EC2 environment and then accessing it through Cloud9. When I create EC2 environments normally, I am given the opportunity to assign an existing key pair, or create a new key pair. This option was not presented to me when I created the environment through Cloud9.

Manley answered 31/12, 2018 at 18:2 Comment(1)
@MartinPrikryl this question is not off-topic. It's a common problem with AWS Cloud9.Wordsmith
O
22

You can SSH into a Cloud9 environment created through Cloud9. The steps are similar to sharing a running app over the internet in the docs, but instead of sharing the app, you share the SSH server.

  1. In AWS Console, find the corresponding EC2 instance.

  2. In the bottom panel, under the Description tab, in Security groups row, click on the link to go to associated security group.

  3. You should now be in Security Groups section. In the bottom panel, under the Inbound tab, click Edit and add:

    • Type: SSH
    • Source: Anywhere

    and click Save.

  4. In Cloud9 terminal, add your public key to ~/.ssh/authorized_keys. Don’t replace the existing keys or elsewise Cloud9 IDE wouldn’t be able to connect to the instance.

  5. You can now SSH into the Cloud9-managed instance using ssh ec2-user@<ip>, or ssh ubuntu@<ip> if using Ubuntu AMI, for other AMIs see default user name for the AMI

Oldfangled answered 15/3, 2019 at 9:26 Comment(4)
Worked like a charm. Just to add up, for PuTTy on Windows, the private key needs to be assigned for authentication settings in order to correctly log in via SSH.Tamie
When you edit the inbound Security Group, do not use "Source: Anywhere", but restrict to your own IP address or a CIDR block range (or a collection of them) which limits the exposure of the EC2 host to IP addresses you manage.Wickiup
Last time I used PuTTy on Windows it was an awful experience IIRC. I use GitBash now (because they won't let us use WSL) and I feel like I can forget about my originating terminal. I do all the windowing remotely in tmux so font size is about all I need in the terminal. Would be grateful for anyone else sharing their preferred terminal on Windows 10.Regent
@Oldfangled Is this configuration possible in a CloudFormation template (i.e. no manual steps)?Galatians
H
1

Cloud9 is managing the underlying EC2 for you so you won't get any extra charges. A terminal is already provided by AWS but you could follow this procedure if you still want to get SSH access to a Cloud9 environment.

Heterotypic answered 31/12, 2018 at 18:12 Comment(3)
So it seems that I can't SSH into a Cloud9 environment that I've created through Cloud9. It seems instead that I have to create the EC2 environment separately, and then connect it to Cloud9 as per the link you provided. Is that correct?Manley
Yes it is. The EC2 environment can be created and then linked to Cloud9Heterotypic
If you want to connect an external GUI for MySQL, then SSH is pretty useful.Wordsmith

© 2022 - 2024 — McMap. All rights reserved.