SFTP 서버에서 사용자 삭제

이 문서에서는 Cloud FTP 서버에서 사용자를 삭제하는 방법을 보여줍니다.

필요한 역할

SFTP 사용자를 삭제하는 데 필요한 권한을 얻으려면 관리자에게 프로젝트에 대한FTP 관리자 (roles/ftp.admin) IAM 역할을 부여해 달라고 요청하세요. 역할 부여에 대한 자세한 내용은 프로젝트, 폴더, 조직에 대한 액세스 관리를 참조하세요.

이 사전 정의된 역할에는 ftp.users.delete 권한이 포함되어 있습니다. SFTP 사용자를 삭제하는 데 필요한

커스텀 역할이나 다른 사전 정의된 역할을 사용하여 이 권한 을 부여받을 수도 있습니다.

SFTP 사용자 삭제

gcloud

  1. 사용자를 대신하여 Cloud Storage 리소스에 액세스하는 서비스 계정을 삭제합니다.

    1. 사용자 서비스 계정의 이메일 주소를 가져옵니다. 예를 들면 USERNAME-sa@PROJECT_ID.. 단계는 사용자 세부정보 가져오기를 참조하세요.

    2. 서비스 계정을 삭제합니다.

      gcloud iam service-accounts delete SERVICE_ACCOUNT

      SERVICE_ACCOUNT를 서비스 계정의 이메일 주소로 바꿉니다.

  2. SFTP 서버에서 사용자를 삭제하려면 gcloud alpha storage ftp users delete 명령어를 실행합니다.

    아래의 명령어 데이터를 사용하기 전에, 다음을 바꿉니다.

    • USERNAME: SFTP 사용자의 사용자 이름입니다.
    • LOCATION_ID: 서버의 위치입니다(예: us-west1).
    • SERVER_ID: 서버 ID입니다.

    다음 명령어를 실행합니다.

    Linux, macOS 또는 Cloud Shell

    gcloud alpha storage ftp users delete USERNAME --location=LOCATION_ID \
        --server=SERVER_ID

    Windows(PowerShell)

    gcloud alpha storage ftp users delete USERNAME --location=LOCATION_ID `
        --server=SERVER_ID

    Windows(cmd.exe)

    gcloud alpha storage ftp users delete USERNAME --location=LOCATION_ID ^
        --server=SERVER_ID
    사용자가 삭제되는 데 몇 초 정도 걸립니다.

REST

  1. 사용자를 대신하여 Cloud Storage 리소스에 액세스하는 서비스 계정을 삭제합니다.

    1. 사용자 서비스 계정의 이메일 주소를 가져옵니다. 예를 들면 USERNAME-sa@PROJECT_ID.. 단계는 사용자 세부정보 가져오기를 참조하세요.

    2. 서비스 계정을 삭제합니다.

      gcloud iam service-accounts delete SERVICE_ACCOUNT

      SERVICE_ACCOUNT를 서비스 계정의 이메일 주소로 바꿉니다.

  2. SFTP 서버에서 사용자를 삭제하려면 servers.users.delete 메서드를 사용합니다.

    요청 데이터를 사용하기 전에 다음을 바꿉니다.

    • PROJECT_ID: Google Cloud 프로젝트 ID
    • LOCATION_ID: 서버의 위치입니다(예: us-west1).
    • SERVER_ID: 서버 ID입니다.
    • USERNAME: SFTP 사용자의 사용자 이름입니다.

    HTTP 메서드 및 URL:

    DELETE https://ftp.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION_ID/servers/SERVER_ID/users/USERNAME

    요청을 보내려면 다음 옵션 중 하나를 펼칩니다.

    응답은 장기 실행 작업을 식별합니다. 사용자가 삭제되는 데 몇 초 정도 걸립니다.

클라이언트 라이브러리

C#

Cloud FTP용 클라이언트 라이브러리를 설치하고 사용하는 방법은 Cloud FTP 클라이언트 라이브러리를 참조하세요. 자세한 내용은 Cloud FTP C# API 참조 문서를 확인하세요.

Cloud FTP에 인증하려면 애플리케이션 기본 사용자 인증 정보를 설정합니다. 자세한 내용은 로컬 개발 환경의 인증 설정을 참조하세요.

using Google.Cloud.Ftp.V1;
using Google.LongRunning;
using Google.Protobuf.WellKnownTypes;
using System.Threading.Tasks;

public sealed partial class GeneratedCloudFtpClientSnippets
{
    /// <summary>Snippet for DeleteUserAsync</summary>
    /// <remarks>
    /// This snippet has been automatically generated and should be regarded as a code template only.
    /// It will require modifications to work:
    /// - It may require correct/in-range values for request initialization.
    /// - It may require specifying regional endpoints when creating the service client as shown in
    ///   https://cloud.google.com/dotnet/docs/reference/help/client-configuration#endpoint.
    /// </remarks>
    public async Task DeleteUserAsync()
    {
        // Create client
        CloudFtpClient cloudFtpClient = await CloudFtpClient.CreateAsync();
        // Initialize request argument(s)
        string name = "projects/[PROJECT]/locations/[LOCATION]/servers/[SERVER]/users/[USER]";
        // Make the request
        Operation<Empty, OperationMetadata> response = await cloudFtpClient.DeleteUserAsync(name);

        // Poll until the returned long-running operation is complete
        Operation<Empty, OperationMetadata> completedResponse = await response.PollUntilCompletedAsync();
        // Retrieve the operation result
        Empty result = completedResponse.Result;

        // Or get the name of the operation
        string operationName = response.Name;
        // This name can be stored, then the long-running operation retrieved later by name
        Operation<Empty, OperationMetadata> retrievedResponse = await cloudFtpClient.PollOnceDeleteUserAsync(operationName);
        // Check if the retrieved long-running operation has completed
        if (retrievedResponse.IsCompleted)
        {
            // If it has completed, then access the result
            Empty retrievedResult = retrievedResponse.Result;
        }
    }
}

Go

Cloud FTP용 클라이언트 라이브러리를 설치하고 사용하는 방법은 Cloud FTP 클라이언트 라이브러리를 참조하세요. 자세한 내용은 Cloud FTP Go API 참조 문서를 확인하세요.

Cloud FTP에 인증하려면 애플리케이션 기본 사용자 인증 정보를 설정합니다. 자세한 내용은 로컬 개발 환경의 인증 설정을 참조하세요.


//go:build examples

package main

import (
	"context"

	ftp "cloud.google.com/go/ftp/apiv1"
	ftppb "cloud.google.com/go/ftp/apiv1/ftppb"
)

func main() {
	ctx := context.Background()
	// This snippet has been automatically generated and should be regarded as a code template only.
	// It will require modifications to work:
	// - It may require correct/in-range values for request initialization.
	// - It may require specifying regional endpoints when creating the service client as shown in:
	//   https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
	c, err := ftp.NewCloudFtpRESTClient(ctx)
	if err != nil {
		// TODO: Handle error.
	}
	defer c.Close()

	req := &ftppb.DeleteUserRequest{
		// TODO: Fill request struct fields.
		// See https://pkg.go.dev/cloud.google.com/go/ftp/apiv1/ftppb#DeleteUserRequest.
	}
	op, err := c.DeleteUser(ctx, req)
	if err != nil {
		// TODO: Handle error.
	}

	err = op.Wait(ctx)
	if err != nil {
		// TODO: Handle error.
	}
}

Java

Cloud FTP용 클라이언트 라이브러리를 설치하고 사용하는 방법은 Cloud FTP 클라이언트 라이브러리를 참조하세요. 자세한 내용은 Cloud FTP Java API 참조 문서를 확인하세요.

Cloud FTP에 인증하려면 애플리케이션 기본 사용자 인증 정보를 설정합니다. 자세한 내용은 로컬 개발 환경의 인증 설정을 참조하세요.

import com.google.api.core.ApiFuture;
import com.google.cloud.ftp.v1.CloudFtpClient;
import com.google.cloud.ftp.v1.DeleteUserRequest;
import com.google.cloud.ftp.v1.UserName;
import com.google.longrunning.Operation;

public class AsyncDeleteUser {

  public static void main(String[] args) throws Exception {
    asyncDeleteUser();
  }

  public static void asyncDeleteUser() throws Exception {
    // This snippet has been automatically generated and should be regarded as a code template only.
    // It will require modifications to work:
    // - It may require correct/in-range values for request initialization.
    // - It may require specifying regional endpoints when creating the service client as shown in
    // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
    try (CloudFtpClient cloudFtpClient = CloudFtpClient.create()) {
      DeleteUserRequest request =
          DeleteUserRequest.newBuilder()
              .setName(UserName.of("[PROJECT]", "[LOCATION]", "[SERVER]", "[USER]").toString())
              .setForce(true)
              .build();
      ApiFuture<Operation> future = cloudFtpClient.deleteUserCallable().futureCall(request);
      // Do something.
      future.get();
    }
  }
}

Node.js

Cloud FTP용 클라이언트 라이브러리를 설치하고 사용하는 방법은 Cloud FTP 클라이언트 라이브러리를 참조하세요. 자세한 내용은 Cloud FTP Node.js API 참조 문서를 확인하세요.

Cloud FTP에 인증하려면 애플리케이션 기본 사용자 인증 정보를 설정합니다. 자세한 내용은 로컬 개발 환경의 인증 설정을 참조하세요.

/**
 * This snippet has been automatically generated and should be regarded as a code template only.
 * It will require modifications to work.
 * It may require correct/in-range values for request initialization.
 * TODO(developer): Uncomment these variables before running the sample.
 */
/**
 *  Required. Name of the resource
 */
// const name = 'abc123'
/**
 *  Optional. If set to true, the request will force the deletion of the User.
 */
// const force = true

// Imports the Ftp library
const {CloudFtpClient} = require('@google-cloud/ftp').v1;

// Instantiates a client
const ftpClient = new CloudFtpClient();

async function callDeleteUser() {
  // Construct request
  const request = {
    name,
  };

  // Run request
  const [operation] = await ftpClient.deleteUser(request);
  const [response] = await operation.promise();
  console.log(response);
}

callDeleteUser();

PHP

Cloud FTP용 클라이언트 라이브러리를 설치하고 사용하는 방법은 Cloud FTP 클라이언트 라이브러리를 참조하세요. 자세한 내용은 Cloud FTP PHP API 참조 문서를 확인하세요.

Cloud FTP에 인증하려면 애플리케이션 기본 사용자 인증 정보를 설정합니다. 자세한 내용은 로컬 개발 환경의 인증 설정을 참조하세요.

use Google\ApiCore\ApiException;
use Google\ApiCore\OperationResponse;
use Google\Cloud\Ftp\V1\Client\CloudFtpClient;
use Google\Cloud\Ftp\V1\DeleteUserRequest;
use Google\Rpc\Status;

/**
 * Deletes a single User.
 *
 * @param string $formattedName Name of the resource
 *                              Please see {@see CloudFtpClient::userName()} for help formatting this field.
 */
function delete_user_sample(string $formattedName): void
{
    // Create a client.
    $cloudFtpClient = new CloudFtpClient();

    // Prepare the request message.
    $request = (new DeleteUserRequest())
        ->setName($formattedName);

    // Call the API and handle any network failures.
    try {
        /** @var OperationResponse $response */
        $response = $cloudFtpClient->deleteUser($request);
        $response->pollUntilComplete();

        if ($response->operationSucceeded()) {
            printf('Operation completed successfully.' . PHP_EOL);
        } else {
            /** @var Status $error */
            $error = $response->getError();
            printf('Operation failed with error data: %s' . PHP_EOL, $error->serializeToJsonString());
        }
    } catch (ApiException $ex) {
        printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
    }
}

/**
 * Helper to execute the sample.
 *
 * This sample has been automatically generated and should be regarded as a code
 * template only. It will require modifications to work:
 *  - It may require correct/in-range values for request initialization.
 *  - It may require specifying regional endpoints when creating the service client,
 *    please see the apiEndpoint client configuration option for more details.
 */
function callSample(): void
{
    $formattedName = CloudFtpClient::userName('[PROJECT]', '[LOCATION]', '[SERVER]', '[USER]');

    delete_user_sample($formattedName);
}

Python

Cloud FTP용 클라이언트 라이브러리를 설치하고 사용하는 방법은 Cloud FTP 클라이언트 라이브러리를 참조하세요. 자세한 내용은 Cloud FTP Python API 참조 문서를 확인하세요.

Cloud FTP에 인증하려면 애플리케이션 기본 사용자 인증 정보를 설정합니다. 자세한 내용은 로컬 개발 환경의 인증 설정을 참조하세요.

# This snippet has been automatically generated and should be regarded as a
# code template only.
# It will require modifications to work:
# - It may require correct/in-range values for request initialization.
# - It may require specifying regional endpoints when creating the service
#   client as shown in:
#   https://googleapis.dev/python/google-api-core/latest/client_options.html
from google.cloud import ftp_v1


def sample_delete_user():
    # Create a client
    client = ftp_v1.CloudFtpClient()

    # Initialize request argument(s)
    request = ftp_v1.DeleteUserRequest(
        name="name_value",
    )

    # Make the request
    operation = client.delete_user(request=request)

    print("Waiting for operation to complete...")

    response = operation.result()

    # Handle the response
    print(response)

Ruby

Cloud FTP용 클라이언트 라이브러리를 설치하고 사용하는 방법은 Cloud FTP 클라이언트 라이브러리를 참조하세요. 자세한 내용은 Cloud FTP Ruby API 참조 문서를 확인하세요.

Cloud FTP에 인증하려면 애플리케이션 기본 사용자 인증 정보를 설정합니다. 자세한 내용은 로컬 개발 환경의 인증 설정을 참조하세요.

require "google/cloud/ftp/v1"

##
# Snippet for the delete_user call in the CloudFtp service
#
# This snippet has been automatically generated and should be regarded as a code
# template only. It will require modifications to work:
# - It may require correct/in-range values for request initialization.
# - It may require specifying regional endpoints when creating the service
# client as shown in https://cloud.google.com/ruby/docs/reference.
#
# This is an auto-generated example demonstrating basic usage of
# Google::Cloud::Ftp::V1::CloudFtp::Rest::Client#delete_user.
#
def delete_user
  # Create a client object. The client can be reused for multiple calls.
  client = Google::Cloud::Ftp::V1::CloudFtp::Rest::Client.new

  # Create a request. To set request fields, pass in keyword arguments.
  request = Google::Cloud::Ftp::V1::DeleteUserRequest.new

  # Call the delete_user method.
  result = client.delete_user request

  # The returned object is of type Gapic::Operation. You can use it to
  # check the status of an operation, cancel it, or wait for results.
  # Here is how to wait for a response.
  result.wait_until_done! timeout: 60
  if result.response?
    p result.response
  else
    puts "No response received."
  end
end

다음 단계