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.

Sean McCarthy
  • 4,838
  • 8
  • 39
  • 61

2 Answers2

21

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

Thai
  • 10,746
  • 2
  • 45
  • 57
  • 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. – Filip Filipovic Jul 04 '19 at 11:02
  • 1
    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. – ojacques Apr 25 '22 at 10:15
  • 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. – NeilG Apr 05 '23 at 09:47
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.

Quentin Revel
  • 1,400
  • 8
  • 11
  • 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? – Sean McCarthy Dec 31 '18 at 19:28
  • 1
    Yes it is. The EC2 environment can be created and then linked to Cloud9 – Quentin Revel Dec 31 '18 at 20:51
  • 1
    If you want to connect an external GUI for MySQL, then SSH is pretty useful. – gagarine Jan 30 '19 at 15:11