10

I have been playing around with Debian on Compute Engine and was wondering how I could SFTP into the server. I can't find any documentation on it and was hoping someone could point me in the right direction.

Thanks!

If this isn't possible, is the best way to manage static sites through SCP?

E. Anderson
  • 3,405
  • 1
  • 16
  • 19
user1156994
  • 101
  • 1
  • 1
  • 5
  • Does this answer your question? [Accessing FTP on Google Compute Engine](https://stackoverflow.com/questions/24958085/accessing-ftp-on-google-compute-engine) – Lulucmy Feb 26 '23 at 14:40

8 Answers8

8

At a high level, these are the steps:

  1. Install and run the gcloud SDK ($ gcloud init)
  2. Generate SSH key ($ gcloud compute ssh)
  3. Setup the FTP client (install and add the key file)
  4. Connect to the VM using the SFTP client

Assuming this question was asked here before this documentation from Google was available.

Also, I have recorded this, it might be helpful:

https://www.youtube.com/watch?v=9ssfE6ODpak

And just an FYI .. if the files that you need to transfer are pretty small in size then maybe you don’t need a SFTP client. Transfer directly from the console as seen here https://youtu.be/HEdXEEYOynE

Naresh MG
  • 633
  • 2
  • 11
  • 19
7

I gave up with gcloud compute copy-files as I couldn't figure out why my instance was not been fetch and something with insufficient permissions, then I started looking into how to sftp into my gcloud instance

this is how I got this to work with filezilla

  1. first I downloaded and run the gcloud sdk : https://cloud.google.com/compute/docs/gcloud-compute/#install

  2. when I first try to connect to an instance from my terminal I was prompted to to create ssh keys, I'm on a mac so the keys were setup in /Users// folder under .ssh/ folder

  3. I got the google_compute_engine private key from the .ssh/ folder and imported that into filezilla > settings > sftp

  4. the host is the ip address of my gcloud vm instance, the user is whatever your username is once you connect to the instance via ssh.. check the prompt: [@]$, your key should be your method of authentication. your remote directory is the same as /home//, server type is unix (I had centos vm in google cloud)

Once my files were uploaded into my directory on my instance from my computer I was able to mv them to wherever I needed those files to be within the gcloud vm instance.

I was again a happy camper.

sources: http://winscp.net/eng/docs/guide_google_compute_engine

Jude Niroshan
  • 4,280
  • 8
  • 40
  • 62
Francisco Cortes
  • 1,121
  • 10
  • 19
  • I have connected to my compute engine instance via filezila sftp, but when i try to upload any file, i got this error: `Command: put "/Users/abdul/signUpPage.html" "signUpPage.html" Error: /opt/bitnami/apache2/htdocs/BRWebApp/signUpPage.html: open for write: permission denied Error: File transfer failed` – Abdul Rehman Sep 20 '17 at 03:27
  • hi, i installed gcloud sdk, but not sure how to "try to connect" in order to get that ssh key prompt. was that a command line you run? i run gcloud init which walked me through the auth and i connected to my instance, but no new keys and not sure where to go from there – Sonic Soul Jan 20 '18 at 20:11
4

You can upload and download files with gcloud compute scp, e.g., upload via:

gcloud compute scp \
     ~/local-dir/file-1 \
     my-instance:~/remote-destination \
     --zone us-central1-a

and download via:

gcloud compute scp \
     my-instance:~/file-1 \
     my-instance:~/file-2 \
     ~/local-dir \
     --zone us-central1-a

The gcloud tool is included in the Google Cloud SDK and comes preinstalled in standard Google Compute Engine VM images.

Misha Brukman
  • 12,938
  • 4
  • 61
  • 78
3

Seem that google computer engine already has SFTP service by default. Following is an excellent step by step instruction using WinSCP as SFTP client to connect to the service. It works perfectly for me on first try.

http://winscp.net/eng/docs/guide_google_compute_engine

Same principle should applies using other FTP client software. Hope will save someone time and effort.

Luke Tsang
  • 31
  • 1
2

ssh, scp and sftp should all work if you specify the instance's IP address. You can use DNS for this if you have a static IP address, or you can use the IP address from gcutil listinstances or the console.

Once you know the IP address of the instance, you'll also need your ssh private key, which is usually at ~/.ssh/google_compute_engine. Then you can connect via sftp as follows:

sftp -o IdentityFile ~/.ssh/google_compute_engine user@host
Misha Brukman
  • 12,938
  • 4
  • 61
  • 78
E. Anderson
  • 3,405
  • 1
  • 16
  • 19
  • Are you missing a `=` in the code? I get error message running your line `sftp -o IdentityFile~/.ssh/google_compute_engine user@123.123`? * Bad configuration option* – Matifou Sep 16 '19 at 21:05
  • I get an error message *Permission denied (publickey)* when running the code (with the =). Seems more is needed than indicating the key? Thanks! – Matifou Sep 16 '19 at 21:07
2

On a Mac or linux OS, use the "gcloud compute config-ssh: command. This will setup the conf file in you .ssh dir and allow you to use ssh, scp & sftp using the alias that is configured in the config file.

gcloud doc for config-ssh https://cloud.google.com/sdk/gcloud/reference/compute/config-ssh

UsmanM
  • 21
  • 3
0

If I understand the question, you want have a SFTP in a instance with Debian.

  1. Try this tutorial

  2. Open the the port 22 in the firewall:

    gcutil addfirewall port-22 --description="Open up port 22." --allowed="tcp:22"

  3. Test with Filezilla Client establishing a SFTP connection.

Have Fun :)

Community
  • 1
  • 1
Carlos Rojas
  • 5,547
  • 2
  • 14
  • 13
0

FileZilla free version and FileZilla Pro both are able to connect to a Google Cloud VM instance of Debian. PuTTY, the other needed program, is also free.

1. Download PuTTY to generate SSH key. I could not connect to instance with key generated by gcommand (the Google Cloud connection). Had to use the PuTTY key to make FileZilla connect.
a. Start PuTTYgen
b. Click "Generate"
c. Do NOT save public key. It makes the key invalid. Copy it from the window instead.
d. Paste it into a text editor and save it as KEYNAME.pub
e. From PuTTY click "Conversions > Export OpenSSH key" and save with extension ".ppk"
f. Do not close PuTTY. You'll need it in a moment.

2. In Google Console edit your Compute Engine instance.
* add the public SSH key (KEYNAME.pub) by pasting in from text editor.

3. Start FileZilla and then other needed programs (described herein)
a. Goto "Edit > Settings"
b. From the left menu select "SFTP".
C. On the right, click "Add key file..." (Navigate to the ppk private key you saved.)
d. Click OK
e. In the toolbar enter "sftp://123.456.789.012" (with your instance's external ip address) in the "Host" field.
f. In PuTTY copy the field "Key comment".
g. In the FileZilla toolbar enter copied "Key comment" from PuTTY into the FileZilla field "Username".
h. On the FileZilla toolbar click "Quickconnect".
i. On FileZilla right pane "Remote site" scroll to the top of the directory tree and click the plus (+) sign, and then click the plus (+) sign again. This loads the entire operating system's directory structure.
j. Scroll down to the last directory "var" and click on it and then expand its plus (+) sign.
k. Directory "www" will popup. Click on that and then its plus sign to expand it.
l. Directory "html" pops up. Click on it. Leave FileZilla—without closing it—and go to "Google Cloud SDK > Google Cloud SDK Shell". Leave it open.
m. Go to Google Cloud console and list your Compute Engine instance. On the right of the instance click the "SSH" dropdown and select "View gcloud command". Copy the command.
n. Paste that command into the "Google Cloud SDK Shell". That will launch the PuTTY terminal and give you a command prompt for the Linux system.
o. Type the command "sudo chmod -v 777 /var/www/*" (That's an asterisk at the end.)
p. Go back to FileZilla and drag your web files into the right pane "html" directory. You may have to click "Disconnect" on the toolbar to be able to write to that directory with new permissions. (It's the icon of the computer with the red "X".) Then click "Quickconnect" again and list the directories as before.
q. When you have finished uploading your files go to the PuTTY (or whatever terminal opened when you pasted in the gcommand string) and enter this command: "sudo chmod -v 755 /var/www/*" to reset the permission of the "www" directory.


Bang! You're done.

With FileZilla you can manipulate the files of the entire Linux system. I just used it for the web directory.