Post

SSH Invalid PublicKey

SSH, or Secure Shell, is a widely used protocol for secure remote access to systems. However, when attempting to connect to a server using SSH, you may encounter a “permission denied (publickey)” error. This guide will help you troubleshoot and resolve this issue.

Cause of the Error

The “permission denied (publickey)” error commonly occurs due to incorrect permissions on key files or other SSH configuration issues.

Solutions

1. Check SSH Key Permissions (Client and Server Side)

  • Client Side: Ensure correct permissions on the private key (id_rsa) and public key (id_rsa.pub) files.
1
2
chmod 600 ~/.ssh/id_rsa
chmod 644 ~/.ssh/id_rsa.pub
  • Server Side: Verify permissions on the authorized_keys file.
1
sudo chmod 600 ~/.ssh/authorized_keys

Additional Fix Server/Client

  • Check SSH Configs Directory Permissions: Ensure that the user ssh directory on the server has appropriate permissions (drwx------).
1
chmod go-w ~/.ssh
  • go-w: This specifies the permissions to set. In this case, it means “remove write (w) permission for group (g) and others (o)”. So, it removes the write permission for anyone other than the owner of the directory.

2. Use Verbose Logging for Debugging

To get more detailed information about the SSH connection process, use verbose mode:

1
ssh -vvv user@hostname
  • -vvv: Specifies verbose mode, providing detailed debugging information.

Conclusion

By following these steps, you should be able to troubleshoot and resolve the “permission denied (publickey)” error when using SSH for remote connections.

This post is licensed under CC BY 4.0 by the author.