I’m experimenting with private/public subnets in a VPC and have the following setup:
VPC set up using 10.24.0.0/16
3 x public subnets: 10.24.0.0/24, 10.24.1.0/24 & 10.24.2.0/24
3 x private subnets: 10.24.20.0/24, 10.24.21.0/24 & 10.24.22.0/24
I have a “public” ec2 instance spun up in the second public subnet and allocated a public ip address. Security group rules are set such that I can ssh in and see the internet from this machine (and run Apache on it, which is visible to the outside world) - this all works as expected.
I have another “private” ec2 instance spun up in the second private subnet, with no public ip address set and security group rules set to allow ICMP traffic and SSH access from 10.24.0.0/16 only.
I can ping the private machine from the public one, but can’t ssh into it. As per the AWS docs, I’m doing
I’m mobile and can’t read your post carefully. However, mistakes I have made myself: using public IP when I should be using private IP and also security groups is a big one. Make sure both machines are in security groups that allow the correct incoming and outgoing. Sorry not more specific but maybe that will help you or others later.
Hmmm. That ssh command works OK from my mac laptop, where I have the .pem file stored (i.e. I can connect and everything looks as I’d expect). It doesn’t work at all (no connection allowed) from the PUBLIC_IP machine because I don’t have the .pem file stored locally on the PUBLIC_IP machine and that’s the only machine that has network access to the 10.24.21.145 one.
What I’d like to achieve would be straightforward access to several private subnet machines via a single bastion host in a public subnet. The AWS docs indicate that the ssh-agent running on my laptop should take care of forwarding the credentials on to the PUBLIC_IP machine but that looks not to be the case(?).
upload .pem used to spawn instance with private ip to the instance with public ip to /home/ubuntu/.ssh/ and use it to connect to the private instance
or instead of uploading ssh key (because it is really not a good idea) - tunnel via instance with public ip (aka jump host) using -A or just forward ssh using -L
if you can just set up IPsec tunnels between VPC and your office branch
Looks like a simple matter of not connecting to the Public instance with key forwarding on the session. Add -A to your initial SSH connection string, also specify the pem file directly with -i and try again
Edit: note, I’m on mobile and the formatting of your post is shite. So apologies if youre already doing what I suggested
if you can ping the private machine from the public one, the routing should be good. as others have said, the most likely cause is not fowarding the correct ssh key. can you drop the pem for the private machine on to the public one and initiate a connection referencing it? (windows guy here - ssh semi-noob)
Thanks - that works (scping the pem to the public one and using it from the public machine to get to the private one). What’s not appears to be the key forwarding part - I’m doing
local_laptop:~$ ssh -A -i keypair.pem public
public:~$ ssh private
and the docs imply that this should work without having to load up the public machine with the keypairs - am I correct in assuming that?
Having woken up to a bunch of responses that indicated that ssh -A should just work, I started digging around in my ssh config files and found this in my local machine ~/.ssh/config file, which I added months/years back. Removing it makes everything work as expected:
Multiplex multiple connections
TCPKeepAlive=yes
ServerAliveInterval=15
ServerAliveCountMax=6
Compression=yes
ControlMaster auto
ControlPath /tmp/%r@%h:%p
ControlPersist yes
Thanks, all, for your replies to this - much appreciated. Now if you’ll excuse me, I have to hit myself with something heavy while chanting “never add stuff to your config files unless you know you need it” ಠ_ಠ