How to SSH into SFTP Gateway
Overview
When you deploy SFTP Gateway via the Google Cloud Marketplace you are unable to specify SSH credentials.
This article covers how to add SSH credentials to your VM, as well as the multiple ways you can connect to your VM using SSH.
Note: SFTP Gateway v3.x uses port 2222
for the SSH protocol, since the SFTP service is bound to port 22
.
Manually Add an SSH Key to the VM
To add your own SSH key to the VM, navigate to the instance in the Google Cloud Console.
Click into the VM Details page, and then click the Edit button at the top.
Under the Security and access section, you will see a subsection labeled SSH Keys.
To add your SSH key, click + Add Item and paste in your SSH key value.
To specify the Linux Admin Username
, add a value after the SSH key. It would look something like this:
ssh-rsa AAAAB.... Bryce
Click the Save button at the bottom and your key should now be added to the VM.
Video Reference
SSH Connect
Another way to connect to the VM via SSH is using the SSH connect feature. However, for this to work you will need to add a Google IP address into your port 2222
firewall rule.
Using the top search-bar, navigate to the Firewall service.
Under the VPC firewall rules, search for the name of your Virtual Machine along with the tcp-2222
rule.
Click into the firewall rule and then click the Edit button at the top.
Under the Source IPv4 ranges section, add this ip address, 35.235.240.0/20
.
This is a Google IP address that allows you to SSH into your VM via SSH connect.
Once you have saved the changes to your firewall rule, go to your VM and under the details tab, go to SSH -> Open in browser window on custom port.
When prompted for the custom port, use port 2222. You should now be connected to the VM.
Connect using the Terminal
Use the following command to SSH into the VM:
ssh -i private.key ubuntu@<ip-address> -p 2222
Replace ubuntu
with the Linux admin user you specified when provisioning the SSH credentials.
Note: You will be prompted to accept the server host key on first connection. The server host key is cached on your client machine, based the hostname and port.
The default SSH port is 22
, so you need to explicitly set port 2222
which is the port OpenSSH listens to.
SCP
When using SCP (which uses SSH behind the scenes), you will also need to specify port 2222
:
scp -P 2222 local-file.tar.gz ubuntu@<ip-address>:/home/ubuntu/
Replace ubuntu
with the Linux admin user you specified when provisioning the SSH credentials.
PuTTY (Windows)
- Open PuTTY and select SSH as the connection type.
- In the Host Name field, enter
username@<public-ip>
- In the Port field, change
22
to2222
- Expand the SSH section on the left, and click on Auth.
- Click on Browse to browse for the
.ppk
key, and click Open when you have selected it. - To launch the SSH session, click Open.