Share on facebook
Share on twitter

Connect as ROOT via SFTP on Google Cloud

If you are using FTP or Sftp as normal user on Google Cloud then you are losing your precious time. 

By connects as root user via SFTP, You can save half of your time on google cloud. 

You can access and modify any file you want, never face permission denied error again.

Let’s get started,

Join Us

Facebook

Twitter

YouTube

Here are the steps for this tutorials,

  • Generate SSH keypairs
  • Add Public key to metadata
  • Modify SSH setting on your Linux VM. 
  • Setup a SFTP client on your Desktop or MAC.

Want Exclusive Tutorials?

Step 1: Generate SSH keypairs

The first step is to create the key pair (Public key and private key) with “root” username on Your Pc or mac.

For windows,

Open puttygen  and  click on generate button. Then type “root” on key comment field. After that click the “save private key” button and save the private key on your desktop. Next, copy the public key.

If you need detail or step by steps guide then follow this blog post.

For Mac,

 On Mac OS , navigate to Go >> Utilities >> Applications >> Terminal.

 Then, execute the command below to generate public and private keys.

ssh-keygen -t rsa -C root -f ~/Desktop/id_rsa

-t rsa = To generate RSA keys.

-f ~/Desktop/id_rsa = “-f ” command is to store those file in a particular directory. Here I  want to store those SSH keys pair in Desktop folder as id_rsa (names of the ssh key file).

Execute that command below to copy the public key.

pbcopy < ~/Desktop/id_rsa.pub

Step 2: Add Public key to Metadata

Now, Log in to Google cloud account. Then, Click on the hamburger menu in the upper left-hand corner of your Google Cloud Platform dashboard. After that, navigate to Compute Engine >> Metadata >> SSH keys.

Now,  Click on Add item and Paste the  Public key which you copied from the previous step. Then  click on the save button.

If you need detail or step by steps guide then follow this blog post.

Step 3: Modify SSH setting on Linux VM.

After you have added the public key in  Google cloud metadata, Navigate to VM Instances. Next click on the “SSH” to open the ssh terminal. You also can use putty for this job.

Now it is time to edit the SSH config file  to allow remote root login. By default, Remote root login is disabled.

Execute this command to edit the ssh config file.

sudo nano /etc/ssh/sshd_config

There are two option for you to choose,  either you can use remote root login with root password or without root password. I recommand you to use it with root password.

It’s up to you whether you want to use password or not.

With root password:

Within that file, find the line that includes PermitRootLogin and modify it to ensure that users can only connect with their SSH key and root password:

/etc/ssh/sshd_config
PermitRootLogin yes 

After that, save the file by pressing  ctrl+o then ctrl+x or ctrl+x >> y >> enter.

Next, To put these changes into effect:

sudo systemctl reload sshd.service

For without root password,

Within that file, find the line that includes PermitRootLogin and modify it to ensure that users can only connect with their SSH key:

/etc/ssh/sshd_config
PermitRootLogin without-password

After that, save the file by pressing ctrl+o then ctrl+x or ctrl+x >> y >> enter.

Next, To put these changes into effect:

sudo systemctl reload sshd.service

Step 4: Setup a SFTP client on Your Destop or MAC.

To complete this step you should have already download and setup a Sftp client on your windows or mac pc.

If you don’t know how to do it then follow this blog and install application such as  Filezilla, Winscp, Cyberduck.

Now, Browse and select the private key (which you save by following the first step) from your pc.

In the above image I am using Filezilla and adding the private key which was created by puttygen application.

For, With root password:

As you can see on the above Image I typed my root password in the ‘password’ field.

If you don’t know your root password then follow this blog.

For, without root password:

If you have changed the ssh config setting to ‘without-password’ then you don’t need to use a password on the  ‘password’ field. Just type root on the user field and click on the connect button.

In the above image I successfully connected as root via SFTP on google cloud VM.

Now it is your time!

I tried my best to provide you a complete tutorial on how to connect as root via SFTP  on Google Cloud. I hope you liked it.

If you need help just drop a comment.

If you benefited from this tutorial, and would like to support my work, please like my Facebook page.

Thanks,

Leave a Comment

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