Guide: Using FileZilla SFTP to Connect MacBook Air M1 to GCP Server

Guide: Using FileZilla SFTP to Connect MacBook Air M1 to a GCP Server

This guide explains how to generate an SSH key on your MacBook Air M1, add it to your Google Cloud instance, configure FileZilla for SFTP access, and handle common permission issues.


Step 1: Generate an SSH Key on MacBook Air

  1. Open Terminal:
    Press Command + Space, type Terminal, and press Enter.

  2. Generate the SSH key:
    Run the following command (replace "your-email@example.com" with your actual email):

    ssh-keygen -t rsa -b 4096 -C "your-email@example.com"
    
  3. Follow the prompts:

    • Press Enter to save the key to the default location (~/.ssh/id_rsa).
    • Optionally, enter a passphrase or press Enter for none.
  4. Copy your public key:
    Run the command below and copy the entire output:

    cat ~/.ssh/id_rsa.pub
    

Step 2: Add the SSH Key to Google Cloud

  1. Log in to Google Cloud Console:
    Navigate to Compute EngineVM Instances.

  2. Select your instance:
    Click on your instance name.

  3. Add the SSH key:

    • Scroll down to the SSH Keys section.
    • Click EditAdd Item.
    • Paste your public key (the one starting with ssh-rsa).
    • Click Save.

Step 3: Install FileZilla on Your MacBook

  1. Download FileZilla:
    Visit the official FileZilla website to download the application.

  2. Install and launch FileZilla.


Step 4: Configure FileZilla for SFTP

  1. Open Site Manager:
    In FileZilla, click FileSite Manager.

  2. Create a new site:
    Click New Site and give it a name (e.g., "GCP Server").

  3. Enter the connection details:

    • Protocol: SFTP - SSH File Transfer Protocol
    • Host: Your GCP instance's external IP (found in Compute Engine under "External IP")
    • Port: 22
    • Logon Type: Key file
    • User: Your GCP username (e.g., your-username)
    • Key file: Click Browse, navigate to ~/.ssh/id_rsa, and select it.
  4. Connect:
    Click Connect to initiate the SFTP session.


Step 5: Adjust Permissions to Prevent "Permission Denied" Errors

If you encounter a "Permission Denied" error when transferring files:

  1. Connect to your GCP instance via SSH:

    ssh -i ~/.ssh/id_rsa your-username@your-external-ip
    
  2. Change directory permissions:
    Replace /path/to/directory with the target directory on your server:

    chmod 777 /path/to/directory
    

Note: Setting permissions to 777 grants full read, write, and execute rights to everyone. Use it only when necessary and consider more secure alternatives for production environments.


Step 6: Transfer Files Using FileZilla

  • Interface Overview:
    FileZilla displays two panels:

    • Left panel: Your local MacBook files.
    • Right panel: Your GCP server files.
  • File Transfers:

    • Upload files: Drag files from the left panel to the right panel.
    • Download files: Drag files from the right panel to the left panel.

Step 7: Configure Firewall Rules (If Needed)

If you are unable to connect, ensure that the Google Cloud Firewall permits SFTP (port 22).

  1. Access Firewall Rules:
    In Google Cloud Console, go to VPC NetworkFirewall Rules.

  2. Create a new firewall rule:

    • Name: allow-sftp
    • Targets: All instances in the network
    • Source IP ranges: 0.0.0.0/0
    • Protocols and ports: TCP: 22
    • Click Create.

Step 8: (Optional) Add Your SSH Key to the SSH Agent

If FileZilla repeatedly asks for the SSH key, add it to your SSH agent to streamline the process:

  1. Start the SSH agent:

    eval "$(ssh-agent -s)"
    
  2. Add your private key:

    ssh-add ~/.ssh/id_rsa
    

🎉 Conclusion

You are now ready to manage your GCP server using FileZilla SFTP from your MacBook Air M1. Enjoy seamless file transfers!

If you have any questions or encounter issues, feel free to seek further assistance.

Comments

Popular posts from this blog