Public Keys

A PublicKey is used to authenticate to Files.com via SFTP (SSH File Transfer Protocol). This method of authentication allows users to use their private key (which is never shared with Files.com) to authenticate themselves against the PublicKey stored on Files.com.

When a user configures their PublicKey, it allows them to bypass traditional password-based authentication, leveraging the security of key-based authentication instead.

Note that Files.com's SSH support is limited to file operations only. While users can securely transfer files and manage their data via SFTP, they do not have access to a full shell environment for executing arbitrary commands.

When generating new SSH keys, here are the available options: Files.com supports multiple SSH key algorithms: RSA (default 4096 bits, range 1024-4096 in 8-bit increments), DSA (1024 bits only), Ed25519 (256 bits), and ECDSA (256, 384, or 521 bits). When generating keys, the system uses these default lengths unless a specific length is specified.

Files.com also supports importing additional key types that cannot be generated: security key types (sk-ecdsa-sha2-nistp256, sk-ssh-ed25519). RSA keys up to 8192 bits are also supported for import.

List Public Keys

SDK Method

publickey.List()

Return Object

[]*PublicKey

Authorization Requirement

Not available to user API keys or sessions from users that are marked as Shared/Bot users.

PublicKeyListParams Fields

FieldDescription
UserId
int64
User ID. Provide a value of 0 to operate the current session's user.

Additional Arguments

Example Request

import (
    "fmt"
    "errors"

    files_sdk "github.com/Files-com/files-sdk-go/v3"
    public_key "github.com/Files-com/files-sdk-go/v3/publickey"
)

publicKeyIterator, err := public_key.List(files_sdk.PublicKeyListParams{UserId: 1})
if err != nil {
    var respErr files_sdk.ResponseError
    if errors.As(err, &respErr) {
        fmt.Println("Response Error Occurred (" + respErr.Type + "): " + respErr.ErrorMessage)
    } else {
        fmt.Printf("Unexpected Error: %s\n", err.Error())
    }
}

for publicKeyIterator.Next() {
    publicKey := publicKeyIterator.publicKey()
}
err = publicKeyIterator.Err()
if err != nil {
    var respErr files_sdk.ResponseError
    if errors.As(err, &respErr) {
        fmt.Println("Response Error Occurred (" + respErr.Type + "): " + respErr.ErrorMessage)
    } else {
        fmt.Printf("Unexpected Error: %s\n", err.Error())
    }
}

Show Public Key

SDK Method

publickey.Find()

Return Object

PublicKey

Authorization Requirement

Not available to user API keys or sessions from users that are marked as Shared/Bot users.

PublicKeyFindParams Fields

FieldDescription
Id
int64
Required
Public Key ID.

Example Request

import (
    "fmt"
    "errors"

    files_sdk "github.com/Files-com/files-sdk-go/v3"
    public_key "github.com/Files-com/files-sdk-go/v3/publickey"
)

publicKey, err := public_key.Find(files_sdk.PublicKeyFindParams{Id: 1})
if err != nil {
    var respErr files_sdk.ResponseError
    if errors.As(err, &respErr) {
        fmt.Println("Response Error Occurred (" + respErr.Type + "): " + respErr.ErrorMessage)
    } else {
        fmt.Printf("Unexpected Error: %s\n", err.Error())
    }
}

Create Public Key

SDK Method

publickey.Create()

Return Object

PublicKey

Authorization Requirement

Not available to user API keys or sessions from users that are marked as Shared/Bot users.

PublicKeyCreateParams Fields

FieldDefaultDescription
UserId
int64
User ID. Provide a value of 0 to operate the current session's user.
Title
string
Required
Internal reference for key.
PublicKey
string
Actual contents of SSH key.
GenerateKeypair
boolean
falseIf true, generate a new SSH key pair. Can not be used with public_key
GeneratePrivateKeyPassword
string
Password for the private key. Used for the generation of the key. Will be ignored if generate_keypair is false.
GenerateAlgorithm
string
"rsa"Type of key to generate. One of rsa, dsa, ecdsa, ed25519. Used for the generation of the key. Will be ignored if generate_keypair is false.
GenerateLength
int64
Length of key to generate. If algorithm is ecdsa, this is the signature size. Used for the generation of the key. Will be ignored if generate_keypair is false.

Example Request

import (
    "fmt"
    "errors"

    files_sdk "github.com/Files-com/files-sdk-go/v3"
    public_key "github.com/Files-com/files-sdk-go/v3/publickey"
)

publicKey, err := public_key.Create(files_sdk.PublicKeyCreateParams{Title: "My Main Key"})
if err != nil {
    var respErr files_sdk.ResponseError
    if errors.As(err, &respErr) {
        fmt.Println("Response Error Occurred (" + respErr.Type + "): " + respErr.ErrorMessage)
    } else {
        fmt.Printf("Unexpected Error: %s\n", err.Error())
    }
}

Update Public Key

SDK Method

publickey.Update()

Return Object

PublicKey

Authorization Requirement

Not available to user API keys or sessions from users that are marked as Shared/Bot users.

PublicKeyUpdateParams Fields

FieldDescription
Id
int64
Required
Public Key ID.
Title
string
Required
Internal reference for key.

Example Request

import (
    "fmt"
    "errors"

    files_sdk "github.com/Files-com/files-sdk-go/v3"
    public_key "github.com/Files-com/files-sdk-go/v3/publickey"
)

publicKey, err := public_key.Update(files_sdk.PublicKeyUpdateParams{
  Id: 1,
  Title: "My Main Key"
})
if err != nil {
    var respErr files_sdk.ResponseError
    if errors.As(err, &respErr) {
        fmt.Println("Response Error Occurred (" + respErr.Type + "): " + respErr.ErrorMessage)
    } else {
        fmt.Printf("Unexpected Error: %s\n", err.Error())
    }
}

Delete Public Key

SDK Method

publickey.Delete()

Return Object

No return value.

Authorization Requirement

Not available to user API keys or sessions from users that are marked as Shared/Bot users.

PublicKeyDeleteParams Fields

FieldDescription
Id
int64
Required
Public Key ID.

Example Request

import (
    "fmt"
    "errors"

    files_sdk "github.com/Files-com/files-sdk-go/v3"
    public_key "github.com/Files-com/files-sdk-go/v3/publickey"
)

err := public_key.Delete(files_sdk.PublicKeyDeleteParams{Id: 1})
if err != nil {
    var respErr files_sdk.ResponseError
    if errors.As(err, &respErr) {
        fmt.Println("Response Error Occurred (" + respErr.Type + "): " + respErr.ErrorMessage)
    } else {
        fmt.Printf("Unexpected Error: %s\n", err.Error())
    }
}

The PublicKey Object

Some of the methods above return a PublicKey object. The attributes of this object are listed below.

AttributeDescription
Id
int64
Public key ID
WorkspaceId
int64
Workspace ID (0 for default workspace).
Title
string
Public key title
CreatedAt
date-time
Public key created at date/time
ExpiresAt
date-time
Public key expiration date/time
Expired
boolean
Is this public key expired?
Fingerprint
string
Public key fingerprint (MD5)
FingerprintSha256
string
Public key fingerprint (SHA256)
Status
string
Only returned when generating keys. Can be invalid, not_generated, generating, complete
Possible values: error, not_set, to_be_generated, generating, complete
LastLoginAt
date-time
Key's most recent login time via SFTP
GeneratedPrivateKey
string
Only returned when generating keys. Private key generated for the user.
GeneratedPublicKey
string
Only returned when generating keys. Public key generated for the user.
Username
string
Username of the user this public key is associated with
UserId
int64
User ID this public key is associated with