Using FileZilla with Google Cloud Platform on OSX

I recently worked on a project to set up WordPress on the Google Cloud Platform (GCP), the setup of WordPress was straight forward in GCP with the Cloud Launcher. To be able to upload files to the server and change permissions I needed to set up SSH access and to configure FileZilla.

This is how you can launch a WordPress site from GCP.

cloudlauncher.png

I work on an OS X platform and FileZilla is my goto tool for uploading files to a server. This was the first time for me to use GCP – so I was looking through the documentation that Google has provided, pretty straight forward using the GCP gcloud command line.

I’m not so much for the command line, I just went for using the GCP web console to get this done.

GCP web console

I first had to generate a new SSH key-pair on my OS X laptop, here is what I did:

  1. Open a terminal on your workstation and use the ssh-keygen command to generate a new key-pair. Specify the -C flag to add a comment with the username on the instance for whom you will apply the key. The example creates a private key named my-ssh-key, and a public key file named wp-ssh-key.pub.
  2. ssh-keygen -t rsa -f ~/.ssh/wp-ssh-key -C [USERNAME]
  3. where [USERNAME] is the user on the instance for whom you will apply the key. If the user does not exist on the instance, Compute Engine automatically creates it using the username that you specify in this command.
  4. Restrict access to your my-ssh-key private key so that only you can read it and nobody can write to it.
  5. chmod 400 ~/.ssh/wp-ssh-key
  6. Go to the metadata page for your project on the GCP web console.
  7. Click SSH Keys to show a list of project-wide public SSH keys.
metadata-gcp.png
  1. Click the Edit button so that you can modify the public SSH keys in your project.
metadata_add_key.png
  1. Obtain the contents of the ~/.ssh/wp-ssh-key.pub public key file with the cat command.
  2. cat ~/.ssh/wp-ssh-key.pub
  3. The terminal shows your public key in the following form:
  4. ssh-rsa [KEY_VALUE] [USERNAME]
  5. where:
    • [KEY_VALUE] is the generated public key value.
    • [USERNAME] is the user on the instance for whom you will apply the key.
  6. Copy the output from the cat command and paste it as a new item in the list of SSH keys.
  7. At the bottom of the SSH Keys page, click Save to save your new project-wide SSH key.

The public key is now set to work across all of the instances in your GCP project.

Use the ssh command to connect to your instances

  1. Use the ssh command to connect to your GCP instance. Specify your username and the external IP address for the instance that you want to connect to. Your username is the Google username that you use to access your project. For this example, the private key is at ~/.ssh/my-ssh-key.
  2. ssh -i ~/.ssh/wp-ssh-key [USERNAME]@[IP_ADDRESS]
  3. where:
    • [USERNAME] is your username
    • [IP_ADDRESS] is the IP for your instance.

If the connection is successful, you can use the terminal to run commands on your instance. When you are done, use the exit command to disconnect from the instance.

Setting up FileZilla

To make FileZilla work with your GCP project and be able to copy files over from your local laptop you need to add the ~/.ssh/wp-ssh-key to Filezilla. You do that in the following way.

  1. Open FileZilla and select Settings that will open up the settings window.
  2. Select SFTP option
  3. Click on add key file
  4. Select your ~/.ssh/wp-ssh-key from your local laptop.
FileZilla-ssh.png

Miscellaneous config

Depending on the user that you have set up in your ~/.ssh/wp-ssh-key – you might need to do some changes on your server to group management and file permission.

I was using my own name, I got file permission error when I first try to upload, I resolved that by attaching the user in ~/.ssh/wp-ssh-key to the group in the folder I was uploading to. I did this usermod -a -G group username

As this was a WP site installed from the Cloud Launcher, I also had to tweak the file permissions – I used this command chmod -R g+w ./*

Conclusion

That’s all, simple when it works – the first time it can take some time to get it working.

If you have any feedback, you can comment below.


Posted

in

, ,

by

Comments

12 responses to “Using FileZilla with Google Cloud Platform on OSX”

  1. Marcos Avatar
    Marcos

    How can I find my USERNAME?
    I tried to follow your steps, but it didn’t work with Filezilla!

    Error: Server sent disconnect message
    Error: type 2 (protocol error):
    Error: “Too many authentication failures”
    Error: Could not connect to server

    Thanks

    1. torbjornzetterlund Avatar

      What is the username you use to login to your GCP instance that you trying to connect to. You need to generate a key for that username.

      1. Marcos Avatar
        Marcos

        Thanks! I found it!

        I added the key inside GCP console and was able to connect through Mac terminal (ssh -i…), however it is not working with Filezilla!

        I’m getting this error:

        Status: Connecting to XX.XXX.XX.XXX…
        Response: fzSftp started, protocol_version=5
        Command: keyfile “/Users/MYUSERNANE/.ssh/google_compute_engine”
        Command: open “[email protected]” 22
        Command: Trust new Hostkey: Once
        Error: Server sent disconnect message
        Error: type 2 (protocol error):
        Error: “Too many authentication failures”
        Error: Could not connect to server

        Thanks again

        1. torbjornzetterlund Avatar

          Do you have a user in GCP that matches the MYUSERNANE?

          The username must match.

      2. Mohamed Hak Avatar
        Mohamed Hak

        Hi,
        Thank you for this detailed tutorial.
        I just have one question similar to the previous one,
        what do you mean by username you use to login to your GCP?
        Do you mean the google account name?
        because I got it to work but when I try to upload a file it says permission denied.
        even though I can see all my site files in FileZilla.
        Thank you

        1. torbjornzetterlund Avatar

          Mohamed Hak,

          How did you setup WordPress on GCP, did you use the App Launcher and choose the Bitnami package, if so the files on the GCP server is owned by bitnami user, then you have to login with that user to upload the files.

          When I talk about user, is the user on the GCP server that owns the file/folders – you can either create in FileZilla the same user, or you can change your GCP user name to belong to the group bitnami.

  2. KH Avatar
    KH

    Thanks! great tutorial. Worked great for me.

  3. Jackie Avatar
    Jackie

    Hi, I can’t connect to SSH at this step: Use the ssh command to connect to your instances

    It says: Permission denied (publickey,gssapi-keyex,gssapi-with-mic)

    Did the same as your steps. And the username and external address are correct.
    How can I do the next?
    Thank you.

  4. MCGU Avatar
    MCGU

    So helpful – thank you. I used this to help me connect Filezilla to a Bitnami deployed (via Google Marketplace) Joomla instance. I had to use ‘bitnami’ as the user in order to read/ write to the bitnami folders where the Joomla files are stored.

  5. jw Avatar
    jw

    Hello – Thank you for this post.

    I am having a permission error when trying to upload files via File Zilla. Downloading is working.
    —–
    I was using my own name, I got file permission error when I first try to upload, I resolved that by attaching the user in ~/.ssh/wp-ssh-key to the group in the folder I was uploading to. I did this usermod -a -G group username
    —-
    I think I am having the same problems as you, like you stated above. My username in my ssh key file is not the same as the one I have used on the Google cloud compute engine VM instance. I have 775 set on the HTML directory which is the location of the website files and this is the directory I am trying to move files into through FileZilla. What do you think?

    1. Torbjorn Zetterlund Avatar
      Torbjorn Zetterlund

      I think that could be a possible problem, check your directory owner and group for the files in your HTML directory. Check if the owner match your ssh-key – if not generate a new ssh-key and try again.

  6. Rinoy R K Avatar

    Very helpful article. I have been searching for a full day to change few files in Google cloud after my system reset.

    Thank you Torbjorn Zetterlund

Leave a Reply

Your email address will not be published. Required fields are marked *