After installing WordPress on Google Compute Engine, you might need a way to transfer files to the VM. It’s great to have worked on the local machine and upload the changes via file transfer protocol. File transfer protocol needs to be activated first. Then you can use it via any FTP client.
The first obstacle you’ll face after setting up a VM instance is how to transfer files to your Google Cloud VM. It is very obvious because google cloud does not have any shiny option on their dashboard. The basic transfer option is hidden in the SSH section of your VM Instances.
Other than the basic option there are three ways which you can follow to transfer files to Google Cloud. First, using Google Cloud SDK Tools. But that said this option is worse than before, for a newbie. You have to execute the command to transfer a simple file.
Second, using FTP (File Transfer Protocol), but Google Cloud VM instance does not come with a pre-installed FTP server, so you have to set up an FTP server, in order to connect to Google Cloud using FTP.
Third, using SFTP (SSH File Transfer Protocol) which we are going to discuss in the blog. SFTP is more secure than FTP and because Google Cloud instance came with SSH, you don’t need to install anything on your VM instance to transfer files using SFTP.
What is different between FTP and SFTP?
FTP stands for “File Transfer Protocol”. And SFTP stands for “SSH File Transfer Protocol” OR “Secure File Transfer Protocol”.
The main disadvantage of using FTP protocol is security. FTP uses two separate channels, both of which are unencrypted, this means that the information from either of the channel can be intercepted and accessed.
SFTP ensures that data is securely transferred using a private and safe data stream.
It is wise to not have a huge security loophole in your server, that is why you should use only SFTP rather than Ftp. And by the way, Google Cloud does give a click ready FTP setup option.
What is Public and Private keys.
To set up Sftp you need to generate SSH keys pair. These keys pair will help you to encrypt and decrypt data.
Public key: You will add or copy this key to your Google Cloud Metadata. This key will encrypt data which can then only be read by the person who holds the corresponding private key.
Private key: This key file should only remain within your PC. Only a user in possession of a private key that corresponds to the public key at the server will be able to authenticate successfully.
What is Filezilla?
FileZilla is free software, cross-platform FTP / SFTP application, Two different versions of it is available one is Filezilla client and another Filezilla server. You will be using Filezilla client in this tutorial. Filezilla client is available for Windows and macOS.
For Windows PC:
If you are a windows user then the easiest way to generate RSA keys is through PuttyGen. Yes, you can generate a public and private key with other application e.g.. Google SDK etc.
Generate public and private Keys
To generate Public and private RSA key follow these steps below:
- Download and install PuTTy.
- Generate Public and private keys using Puttygen.
- Add Public key to Google Cloud.
- Use one public key for only one VM Instances
OR - Use one public key for all the VM Instances.
- Use one public key for only one VM Instances
1. Download and install PuTTy
Firstly, you need to do is to download Putty. HERE is the link to Download putty.
Next Step is to install putty on your computer.
2. Generate Public and private keys using Puttygen
Now open PuTTYgen to generate Public and Private keys.
Click on “generate” and move your mouse to create public and private keys.
I recommended you to change the key comment field to something recognizable and easy to type, as this will become a user name later!
Save the private key. Later, This private key will be needed to configure putty.
Copy the Public key
I recommended you to also save the public key by clicking on “Save public key” button.
3. Add Public key to Google Cloud
After your SSH key Files have been generated, You have to add your SSH public key file in your Google Cloud Project or Instances Metadata section.
You can use one SSH keys pair for all the available VM Instances or one SSH keys pair for only one Instances.
3.1 Use one public key for only one Vm Instances
To add SSH Public key to only a specific VM Instances follow the steps below.
Click on the hamburger menu in the upper left-hand corner of your Google Cloud Platform dashboard.
After that navigate to Compute Engine >> VM Instances.
Open the setting section by clicking over the name of your VM instance.
Here I am running a Debian 9.9 WordPress server. It does not matter what you are running.
Click on the edit Button.
After that scroll down and click on the “Show and edit” Button.
You need to paste the Public key which you copied earlier from the puttygen application.
setup Filezilla
To set up Filezilla client on your windows PC follow the steps below. Those are Steps for this tutorial.
- Download and Install Filezilla.
- Configure Filezilla.
- Connect to Google Cloud.
- Troubleshooting: Can not upload or edit files.
1. Download and Install Filezilla
Goto the link below and download a suitable version of filezilla application for your 64bit or 32 bit windows pc.
DOWNLOAD: Filezilla Client.
After you download the filezilla client run it on your windows PC.
2. Configure Filezilla.
After you installed Filezilla Client, Open it and navigate to Edit >> Settings.
Then Click on SFTP. After that click on Add key file. And select the private key file which you saved from PuttyGen. Click on “OK” button to save the settings.
Now navigate to File >> Site Manager.
After that click on New Site and give a name. Then click on the Protocol and choose “SFTP – SSH File Transfer Protocol.
Copy your External IP and place it on the Host Section (step 3 in this image). In the username field, type your PuTTyGen key comment. Then click on the OK button to save the setting.
3. Connect to Google Cloud
To access your VM Instances files navigate to File >> Site Manager. Then click on Connect button.
Here what look like when you’ve connected successfully.
4. Troubleshooting: Can not upload or edit files
If you are seeing this error below
Error // open for write:permission denied
Error File transfer failed
It means that you don’t have proper permission to modify or upload your files. You have to change the file or folder permission to 777.
How change file or folder write permission on google cloud
Connect to your VM using SSH. If you want to add write permission to a single file then execute the following command. If you want to add write permission to the whole directory or folder just add -R
flag to it.
sudo chmod 777 /path-to-single-file
sudo chmod -R 777 /path-to-folder -- folder name without slash '/'
Thanks for reading.