Software⏱️ 2 min read📅 2026-05-31

How to Fix: Permission denied (publickey) when SSH Access to Amazon EC2 instance

SSH permission denied error when connecting to Amazon EC2 instance.

Quick Answer: Check the file permissions and ensure the private key is in the correct format. Try using a different port or protocol, such as SFTP via FileZilla.

You are getting this error because the ownership of your pem file is set to a group, not just you. When you run the `chmod` command with `600`, it changes the permissions so that only the owner (you) and no one else can read or write to the file.

✅ Best Solutions to Fix It

Method 1: Correct Ownership

  1. Step 1: Change the ownership of your pem file to just you using the command `chown kashif serverkey.pem

Method 2: Update SSH Config File

  1. Step 1: Open your SSH config file in a text editor and add the following lines under the `[User kashif]` section: `Host ec2-54-227-242-179.compute-1.amazonaws.com UserID 1000

🎯 Final Words

To connect with FileZilla, you can upload/download files by navigating to the SFTP tab in your FileZilla client and entering the IP address of your EC2 instance or using a pre-configured connection. Make sure to select the correct pem file and port (22) when connecting.

Did this fix your problem?

If not, try searching for specific error codes.

🔍 Search Error Database

❓ Frequently Asked Questions