Here are some methods you can try to resolve the 'Permission denied (publickey)' or 'Authentication failed, permission denied' errors
- Verify the User Name: Ensure that you’re using the correct user name for your AMI.
- Check File Permissions: Verify that the file permissions within the operating system are correct and that the correct SSH public key is in the
authorized_keys
file. - Enter Key File Password: Enter the password for your key file or use
ssh-agent
to load the key automatically. - Check Instance’s Permissions: Check that the instance’s permissions are correct and the correct SSH public key is in the
authorized_keys
file.
If you copied your SSH keys from another source, you might encounter a permission denied error. This can happen if the file permissions on the SSH keys are too open. It’s simply not allowed to have 777 permissions on the public or private keys. You can set the following permissions on the ssh directory and its files:
.ssh directory: 700 (drwx------)
public keys: 644 (-rw-r--r--)
private keys: 600 (-rw-------)
authorized_keys: 600 (-rw-------)
known_hosts: 600 (-rw-------)
config: 600 (-rw-------)
You can change these permissions using chmod
command.
If these methods don’t work, you might need to check your SSH configuration file or restart your SSH service.