SSH error on Linux. Fix denied (publickey) permission

This quick tutorial will show you how to fix ssh error. “Sign_and_send_pubkey: signing failed: agent refused operation Permission denied (publickey)” on Linux.

If you are trying to connect to a remote server via SSH, you may encounter an Access Denied error. This error can occur for a number of reasons. And the fix for this problem depends on the cause of the error.

In our case, we had public and private keys stored on the desktop Ubuntu 04.16. After Ubuntu 18.04 was released, we decided to upgrade to this new version. We prefer a fresh install over distribution updates.

So, we made a backup of the main folders in my home directory, including the .ssh folder, which contained the public and private keys on an external drive. After installing Ubuntu 18.04, we restored everything, including the SSH keys.

Now, when we tried to connect to the remote server using ssh, we thought it would work right away, because there were the same public and private keys.

But it didn’t work. SSH gave this error:

sign_and_send_pubkey: signing failed: agent refused operation
[email protected]: Permission denied (publickey).

If you are in a similar situation where you copied your SSH keys from another source, let me show you how to fix this SSH error.

Error fix denial of rights (publicickey)

So the problem is with file resolution. You see, when we copied the files, the USB stick was in Microsoft’s FAT file format. This file does not support UNIX / Linux file permissions.

And hence the permissions on the copied ssh keys were changed to 777.

File permissions are too open for SSH. It just isn’t allowed to have 777 for public or private keys. And that’s why SSH refused to connect.

ls -l .ssh
-rwxrwxrwx 1 andreyex andreyex 1766 Nov 23  2017 id_rsa
-rwxrwxrwx 1 andreyex andreyex  398 Nov 23  2017
-rwxrwxrwx 1 andreyex andreyex 4214 Sep 15 12:38 known_hosts

The private key must have read / write permissions only for the user and other permissions for the group and others.

You have to change the permission using the CHMOD command:

chmod 600 ~/.ssh/id_rsa

Likewise, the public key should not have write and execute permissions for the group and others.

chmod 644 ~/.ssh/

Now that you’ve set the correct permissions, you can connect to ssh again. It will ask for an administrator password to unlock the keys. Enter the administrator password.

This also taught us one lesson, copying and pasting files is a bad idea and a proper backup must be done differently, all files will have dangerous 777 permissions on them. I had to recursively change the file permissions in the entire Home directory and trust me, it was not very pleasant.

As we said earlier, there can be various reasons for this error. For permission to open file issue, this hotfix should help you fix the Permission denied (publickey) error in SSH.

Let us know in the comments section if the fix works for you or not. Also offer your opinion on copying ssh keys to other computers.

Please disable your ad blocker or whitelist this site!