Trouble SSHing from Public EC2 to Private Instance

0
3
Asked By CuriousCat83 On

I'm trying to SSH into an EC2 instance located in a private subnet from one in a public subnet, but I'm encountering a 'permission denied (publickey)' error. I've been following instructions to add my RSA key to the private instance during its creation by including it in the user data section. The commands I'm using create the necessary directories and set the correct permissions for the key file. I've also verified that the security group for the private instance allows inbound SSH traffic. Where could I be going wrong? Here are the commands I inserted into the user data, with the public key placeholder to be replaced:

```bash
#!/bin/bash
mkdir -p /home/ubuntu/.ssh
echo "PASTE_WEBSERVER_PUBLIC_KEY_STRING_HERE" >> /home/ubuntu/.ssh/authorized_keys
chown -R ubuntu:ubuntu /home/ubuntu/.ssh
chmod 700 /home/ubuntu/.ssh
chmod 600 /home/ubuntu/.ssh/authorized_keys
```

2 Answers

Answered By CloudWizard99 On

Did you remember to include the pound sign in the shebang? Just checking because if you miss that, it could cause issues with your commands running properly.

CuriousCat83 -

No worries, I've got the pound sign in there, but I appreciate the thought!

Answered By TechieTom42 On

What username are you using to connect? The default username for Ubuntu instances is usually 'ubuntu'. Double-check to make sure you're using that!

CuriousCat83 -

Yes, I'm using the default 'ubuntu' user.

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.