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 Function

PublicKey.list()

Return Object

ListIterator<PublicKey>

Authorization Requirement

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

Function Arguments

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

Additional Arguments

Example Request

import com.files.ListIterator;
import com.files.exceptions.*;
import com.files.exceptions.ApiErrorException.*;
import com.files.models.PublicKey;

try {
  HashMap<String, Object> parameters = new HashMap<>();
  parameters.put("user_id", 1);
  
  ListIterator<PublicKey> publicKeys = PublicKey.list(parameters);
  for (PublicKey publicKey : publicKeys.listAutoPaging()) {
    // Operate on publicKey
  }
} catch (NotAuthenticatedException e) {
  System.out.println("Authentication Error Occurred (" + e.getClass().getName() + "): " + e.getMessage());
} catch (SdkException e) {
  System.out.println("Unknown Error Occurred (" + e.getClass().getName() + "): " + e.getMessage());
}

Show Public Key

SDK Function

PublicKey.find()

Return Object

PublicKey

Authorization Requirement

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

Function Arguments

ArgumentDescription
id
int64
Required
Public Key ID.

Example Request

import com.files.exceptions.*;
import com.files.exceptions.ApiErrorException.*;
import com.files.models.PublicKey;

try {
  HashMap<String, Object> parameters = new HashMap<>();
  PublicKey publicKey = PublicKey.find(id, parameters);
  // Operate on publicKey
} catch (NotAuthenticatedException e) {
  System.out.println("Authentication Error Occurred (" + e.getClass().getName() + "): " + e.getMessage());
} catch (SdkException e) {
  System.out.println("Unknown Error Occurred (" + e.getClass().getName() + "): " + e.getMessage());
}

Create Public Key

SDK Function

PublicKey.create()

Return Object

PublicKey

Authorization Requirement

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

Function Arguments

ArgumentDefaultDescription
user_id
int64
User ID. Provide a value of 0 to operate the current session's user.
title
string
Required
Internal reference for key.
public_key
string
Actual contents of SSH key.
generate_keypair
boolean
falseIf true, generate a new SSH key pair. Can not be used with public_key
generate_private_key_password
string
Password for the private key. Used for the generation of the key. Will be ignored if generate_keypair is false.
generate_algorithm
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.
generate_length
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 com.files.exceptions.*;
import com.files.exceptions.ApiErrorException.*;
import com.files.models.PublicKey;

try {
  HashMap<String, Object> parameters = new HashMap<>();
  parameters.put("title", "My Main Key");
  
  PublicKey publicKey = PublicKey.create(parameters);
  // Operate on publicKey
} catch (NotAuthenticatedException e) {
  System.out.println("Authentication Error Occurred (" + e.getClass().getName() + "): " + e.getMessage());
} catch (SdkException e) {
  System.out.println("Unknown Error Occurred (" + e.getClass().getName() + "): " + e.getMessage());
}

Update Public Key

SDK Function

publicKey.update();

Return Object

PublicKey

Authorization Requirement

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

Attribute Setters

SetterDescription
setTitle
string
Required
Internal reference for key.

Example Request

import com.files.exceptions.*;
import com.files.exceptions.ApiErrorException.*;
import com.files.models.PublicKey;

try {
  // Find the publicKey object by its id.
  PublicKey publicKey = PublicKey.find(id, null);
  HashMap<String, Object> parameters = new HashMap<>();
  parameters.put("title", "My Main Key");
  publicKey.update(parameters);
} catch (NotAuthenticatedException e) {
  System.out.println("Authentication Error Occurred (" + e.getClass().getName() + "): " + e.getMessage());
} catch (SdkException e) {
  System.out.println("Unknown Error Occurred (" + e.getClass().getName() + "): " + e.getMessage());
}

Delete Public Key

SDK Function

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.

Example Request

import com.files.exceptions.*;
import com.files.exceptions.ApiErrorException.*;
import com.files.models.PublicKey;

try {
  // Find the publicKey object by its id.
  PublicKey publicKey = PublicKey.find(id, null);
  publicKey.delete(null);
} catch (NotAuthenticatedException e) {
  System.out.println("Authentication Error Occurred (" + e.getClass().getName() + "): " + e.getMessage());
} catch (SdkException e) {
  System.out.println("Unknown Error Occurred (" + e.getClass().getName() + "): " + e.getMessage());
}

The PublicKey Object

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

AttributeDescription
id
int64
Public key ID
workspace_id
int64
Workspace ID (0 for default workspace).
title
string
Public key title
created_at
date-time
Public key created at date/time
expires_at
date-time
Public key expiration date/time
expired
boolean
Is this public key expired?
fingerprint
string
Public key fingerprint (MD5)
fingerprint_sha256
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
last_login_at
date-time
Key's most recent login time via SFTP
generated_private_key
string
Only returned when generating keys. Private key generated for the user.
generated_public_key
string
Only returned when generating keys. Public key generated for the user.
username
string
Username of the user this public key is associated with
user_id
int64
User ID this public key is associated with