How can one troubleshoot the error "Unable to open public key file" in PHP SSH connections?

The error "Unable to open public key file" in PHP SSH connections typically occurs when the specified public key file cannot be found or accessed. To troubleshoot this issue, ensure that the correct file path is provided and that the file has the appropriate permissions set. Additionally, double-check the file extension and ensure that the file exists in the specified location.

<?php
$ssh = ssh2_connect('example.com', 22);
$pubKey = '/path/to/public_key.pub';

if (ssh2_auth_pubkey_file($ssh, 'username', $pubKey, 'private_key')) {
    echo "Public key authentication successful";
} else {
    echo "Unable to open public key file";
}
?>