This document shows how to update the Secure Shell (SSH) keys that a Cloud FTP user can use to connect to an SFTP server.
Before you begin
Get the user's public key from each SSH key pair that they will use to connect to the server. A user can have a maximum of 10 public keys.
If the user doesn't have an SSH key pair, use the following steps to generate one.
Generate an SSH key pair
Which key format do you need?
The key format that you need depends on which client you use to connect to the SFTP server. For more information, see Supported SFTP clients.
PEM format
-
To create an OpenSSH key pair (PEM format), use the
ssh-keygenutility.On the client machine that will connect to the SFTP server, run the following command:
ssh-keygen -t rsa -b 4096 -f ~/.ssh/KEY_PAIR_NAME
Replace
KEY_PAIR_NAMEwith a name for the key pair, such assftp_user_key. -
Extract the public key:
cat ~/.ssh/KEY_PAIR_NAME.pub
PPK format
-
To create a PuTTY key pair (PPK format), use the
PuTTYgentool.On the client machine that will connect to the SFTP server, run the following command:
puttygen -t rsa -b 4096 -o KEY_PAIR_NAME.ppk
Replace
KEY_PAIR_NAMEwith a name for the key pair, such assftp_user_key. -
Extract the public key:
puttygen -L KEY_PAIR_NAME.ppk
-
Required roles
To get the permission that
you need to update SFTP users,
ask your administrator to grant you the
FTP Admin (roles/ftp.admin) IAM role on your project.
For more information about granting roles, see Manage access to projects, folders, and organizations.
This predefined role contains the
ftp.users.update
permission,
which is required to
update SFTP users.
You might also be able to get this permission with custom roles or other predefined roles.
Update an SFTP user's SSH keys
gcloud
To update an SFTP user's SSH keys, run the
gcloud alpha storage ftp users update command.
Before using any of the command data below, make the following replacements:
- CREDENTIAL_NAME: a unique name to identify the user credentials.
- SSH_PUBLIC_KEY: the body of the user's SSH public key, in OpenSSH format. For
example,
ssh-rsa AAAAB3NzaC1ycRexample.... - USERNAME: the SFTP user's username.
- LOCATION_ID: the location of the server, such
as
us-west1. - SERVER_ID: the server ID.
To configure multiple public keys for a user, provide multiple credentials in the
credentials.json file.
Save the following content in a file called credentials.json:
[ { "credentialName": "CREDENTIAL_NAME", "credentialType": "PUBLIC_KEY", "sshPublicKeyBody": "SSH_PUBLIC_KEY" } ]
Execute the following command:
Linux, macOS, or Cloud Shell
gcloud alpha storage ftp users update USERNAME --location=LOCATION_ID \ --server=SERVER_ID --user-credentials-from-file=credentials.json
Windows (PowerShell)
gcloud alpha storage ftp users update USERNAME --location=LOCATION_ID ` --server=SERVER_ID --user-credentials-from-file=credentials.json
Windows (cmd.exe)
gcloud alpha storage ftp users update USERNAME --location=LOCATION_ID ^ --server=SERVER_ID --user-credentials-from-file=credentials.json
REST
To update an SFTP user's SSH keys, use the
servers.users.patch method.
In the updateMask query parameter, provide the userCredentials field.
Before using any of the request data, make the following replacements:
- PROJECT_ID: the Google Cloud project ID of the server.
- LOCATION_ID: the location of the server, such
as
us-west1. - SERVER_ID: the server ID.
- USERNAME: the SFTP user's username.
- CREDENTIAL_NAME: a unique name to identify the user credentials.
- SSH_PUBLIC_KEY: the body of the user's SSH public key, in OpenSSH format. For
example,
ssh-rsa AAAAB3NzaC1ycRexample....
To configure multiple public keys for a user, provide multiple credentials in the
userCredentials list.
HTTP method and URL:
PATCH https://ftp.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION_ID/servers/SERVER_ID/users/USERNAME?updateMask=userCredentials
Request JSON body:
{
"userCredentials": [
{
"credentialName": "CREDENTIAL_NAME",
"credentialType": "PUBLIC_KEY",
"sshPublicKeyBody": "SSH_PUBLIC_KEY"
}
]
}
To send your request, expand one of these options:
The response identifies a long-running operation. It takes a few seconds for the user to be updated.