Fix your command to:
ssh -p 2222 <username_ec2>@localhost
but a certificate is still needed if you did the port forwarding like so:
ssh -L 2222:localhost:22 -i mycertificate.pem <username_ec2>@<ip_ec2>
I would try the following:
Run another ssh server which listens only on localhost, and doesn't require certificate on another port e.g 2222. See instructions
and then I would port forward to it like so:
ssh -L 2222:localhost:2222 -i mycertificate.pem <username_ec2>@<ip_ec2>
and ssh to it the same way:
ssh -p 2222 <username_ec2>@localhost
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…