Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

mstdmstd's avatar

I got Permission denied (publickey,gssapi-keyex,gssapi-with-mic). error when connect with ssh command

I try to upload my laravel app on aws

I have created a new ASW instance but I got error when try to connect with ssh
$chmod 400  /_work/NSN/__ASW/FilamentBannersServerKeyPair.pem
$ ssh -i  /_work/NSN/__ASW/FilamentBannersServerKeyPair.pem [email protected]
[email protected]: Permission denied (publickey,gssapi-keyex,gssapi-with-mic).

Where FilamentBannersServerKeyPair.pem is security file I have just created My security Group : https://prnt.sc/iz2tl1ii5pAw

My Instance summary: https://prnt.sc/-8QAGxlXEg_A Also I faiid to open link in browser in , as I got

ERR_CONNECTION_REFUSED

What is my options wrong and how that can been fixed?

0 likes
1 reply
LaryAI's avatar
Level 58

The error message "Permission denied (publickey,gssapi-keyex,gssapi-with-mic)" usually means that the SSH client is unable to authenticate with the server using the provided key pair. Here are a few things you can try to fix the issue:

  1. Make sure that the path to the key pair file is correct. Double-check that the file exists and that you have read permissions for it.

  2. Check that the public key associated with the key pair has been added to the authorized_keys file on the server. You can do this by logging in to the AWS console, navigating to the instance, and checking the "SSH key pairs" section under "Security groups". Make sure that the public key associated with the key pair you're using is listed there.

  3. Try specifying the username explicitly in the SSH command. For example, if the username on the server is "ec2-user", you would run:

ssh -i /_work/NSN/__ASW/FilamentBannersServerKeyPair.pem [email protected]
  1. If none of the above works, you can try connecting to the server using the AWS Systems Manager Session Manager. This allows you to connect to the server without using SSH keys. To do this, you'll need to install the SSM agent on the server and configure it to allow session connections. Once that's done, you can connect to the server using the AWS CLI:
aws ssm start-session --target instance-id

Replace "instance-id" with the ID of your AWS instance.

Regarding the "ERR_CONNECTION_REFUSED" error, this usually means that the server is not listening on the port you're trying to connect to. Make sure that the server is running and that the correct port is open in the security group. You can check this by logging in to the AWS console, navigating to the instance, and checking the "Security groups" section. Make sure that the port you're trying to connect to is listed there.

Please or to participate in this conversation.