Skip to content

'Permission denied (publickey).' but terminal ssh connection works fine #1145

Closed

Description

@JPVenson

Hey,

Maybe i am missing the obvious here, but i see no reason why my connection should not work.

The Key is already converted into something SSH.net usable:

-----BEGIN RSA PRIVATE KEY-----
Proc-Type: 4,ENCRYPTED
DEK-Info: AES-128-CBC,

...

-----END RSA PRIVATE KEY-----

and a corresponding ssh call shows the public key is registered on the server correctly:

ssh DOMAIN -l root -i C:\Users\XXXX\.ssh\id_XXXX
-> Works

Then why does this code throws an exception on connect?

var connectionInfo = new ConnectionInfo(uploadTargetHost,
    sshUser,
    new PrivateKeyAuthenticationMethod(sshUser, new PrivateKeyFile(@"C:\Users\XXXX\.ssh\id_XXXX", keyPassword)));

using var client = new SftpClient(connectionInfo);
EventHandler<HostKeyEventArgs> clientOnHostKeyReceived = (sender, e) =>
{
    e.CanTrust = true;
};
client.HostKeyReceived += clientOnHostKeyReceived;
client.Connect();
Renci.SshNet.Common.SshAuthenticationException: 'Permission denied (publickey).'

Activity

  1. Zananok commented on Jul 4, 2023

    @Zananok

    After upgrading the host of my 3 servers to Debian 12, I had the same issue. Works from the terminal, but not from SshNet
    Removed the symlink and create an "original" clean authorized_keys with 600. No success.

    All vms that are debian 11, ubuntu and arch, works fine, just the debian 12 which I get:
    Renci.SshNet.Common.SshAuthenticationException: 'Permission denied (publickey).'

    The solution is to just add PubkeyAcceptedAlgorithms +ssh-rsa on the server config.

    Seems like SshNet's default algo to send is becoming deprecated or at least by default unaccepted by new ssh servers.

    Edit:

    Further research shows that ssh-rsa is using SHA-1 which is not secure, thus the default rejection from ssh servers.
    One ahs to change the sending algo to use SHA-256 and SHA-512 to be accepted without changing the server config to allow a less secure algo.

    Edit2: #825

  2. added this to the 2023.0.0 milestone on Sep 18, 2023
  3. WojciechNagorski commented on Oct 10, 2023

    @WojciechNagorski
    Collaborator
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions