Table of Contents

Method Generate

Namespace
SshSharp
Assembly
SshSharp.dll

Generate(SshKeyType, string?, int)

Generates a new key pair, as ssh-keygen -t does. Write it with SaveAsync(string, string?, CancellationToken) or ToOpenSshPrivateKey(string?, int), and give the server ToAuthorizedKeysLine().

public static SshPrivateKey Generate(SshKeyType type, string? comment = null, int rsaBits = 3072)

Parameters

type SshKeyType

The key type. Ed25519 is the usual choice; ECDSA or RSA where FIPS-approved algorithms are required.

comment string

The comment stored with the key, often user@host.

rsaBits int

The RSA key size: 3072 by default (as ssh-keygen), from 2048 to 16384. Ignored for other types.

Returns

SshPrivateKey

Exceptions

ArgumentOutOfRangeException

rsaBits is not a supported RSA key size.