Share on facebook
Share on twitter

3 Ways to Solve Sftp or Ftp "Permission denied" on Google Cloud

If you are getting permission denied errors while transferring or editing files over SFTP or FTP  then you are in the right place.

In this Article you will find 3 ways to deal with those annoying problems.

Before starting this tutorial, you should have already configured an sFTP client to work with your VM on Google Cloud Platform.

So let’s get started.

Contents

Want Exclusive Tutorials?

Join Us

Facebook

Twitter

YouTube

1. Cause for the permission denied error.

First it is not a bug or system error, it is a mistake which you are making. You are trying to access a file without having proper permissions.

Let me explain a bit, In Linux OS system every file or folder belong to some user and groups. This type of system is there for better security. Unauthorized users and groups can not modify or ever read  a file or directory. Only the ROOT user have the privilege to access any file or folder in the systems,  other user cannot access root user’s files or folders. But root user can access any other users file or folders.

Now back to the cause of the problem,  when you log in to your Google cloud VM via SSH Sftp using software like filezilla, winscp, cyberduck  you’re using a username which does not have that particular file or folder access authority.

NOW, what is the solution? 

There are 3 ways you can avoid this error. 1) Use root user, root has the highest access authority, you will never face this error if you log in as root. 2) Change that file or directory permission to all user. 3) logged as the user of that file or directory.

 

2. Error---

a) Google Cloud Filezilla permission denied error.

If you are seeing this error below,

Error /...  : open for write:permission denied

Error File transfer failed

It means that you don’t have a proper permission to modify or upload that files.

To solve the permission error problem follow the below tutorial.

b) Google Cloud Winscp permission denied error.

When you are trying to upload or modify something and an error pop-up like the above image.

Error,

Permission denied.
Error code: 3
Error message from server: Permission denied.

It means that you don’t have proper access permission on that files or folders.

To solve the permission error problem follow the below tutorial.

a) Google Cloud Cyberduck permission denied error.

Permission denied. Please contact your web hosting service provider for assistance.

41 OPENDIR
42 READDIR
43 READDIR
44 CLOSE
45 OPEN

If you saw a error like the above , It means that you don’t have  access permission to modify that file.

To solve the permission error problem follow the below tutorial.

1st Solution : Upload and move files to desire location.

As I told you earlier,  normally only the owner of the file or directory can access that file or directory.

When you update your metadata on google cloud dashboard, Google cloud create a new user on Linux VM. And the user’s default directory is under /home/your-ssh-public-key user-name.

So, If you upload a file there and later move the file to your desire  destination then you don’t face permission denied error.

 

a) Upload the file

Noted down or remember the user id which you are using to connect via SFTP.

Using your SFTP client, go to /home/your-user-id. In the above Image I am using filezilla ftp SFTP client, and my sftp user id is “username”.

Upload a file in your /home/your-user-id directory.

In the above image I uploaded a png image in /home/username directory.

b) Move the file to desire directory

Login to your google cloud account and click the hamburger menu in the upper left-hand corner of the screen.Next goto Compute Engine. Then goto VM Instances. After that click on SSH button.

Now execute the below command on your terminal.

cd /home/your-user-id

Check the available files

sudo ls

Now move the file to your desire directory

sudo mv /path/to/location

In the above image I am moveing  siteyaar-logo.pnp to /opt/bitnami/apps/htdocs directory.

Now open your SFTP client and check the file.

2nd Solution : Login as root user while using Sftp clients

If you ask me, Login as root user while using Sftp or ftp clients is the best way to use your Google cloud’s VM.

Root user  has the privilege of accessing all the other user’s files. So when using as root user, you will never face the permission denied error again.

This fix will work with any Ftp or  Sftp clients such as filezilla, winscp , cyberduck etc.

Login as root user while using Sftp is a topic of it own, that is why I wrote a separate blog of it. Here is the link.

3rd Solution : Change the file or folder permission

By changing file or directory(folder) permission, you can easily fix you permission denied problem. But if you don’t use it property it can leave a door open for hackers.

Every other website on google suggest you to use these methods but i don’t recommand it, it is unproductive and time-consuming.  I recommand you to use 1st solution.

The process goes like this 1)check the file or directory permission, 2)change the permission to 777, 3) upload or modify a file, 4) change the permission to default.

By using 2)and 3) can solve your problem.

But You should  change the permission to default after the process  for better security.

a) Open SSH terminal

Login to your Google cloud account and click the hamburger menu in the upper left-hand corner of the screen. Next go to Compute Engine. Then go to VM Instances. After that click on SSH button.

b) Check the file or directory default permission

Execute the below command to get the default permission number for that particular file.

sudo stat -c %a  path/to/file/location

In the above Image I am checking the permission of wp-config.php file.

Execute the below command to get the default permission number for that particular directory.

sudo stat -c %a  path/to/directory/location

In the above Image I am checking the permission of htdocs directory.

c) b) Change the file or directory permission to 777

Now, execute the command to chage the permition 777.

sudo chmod 777 /path/to/file/location

In the above Image I am changing the wp-config.php permission to 777.  The number 777 means anyone can use or modify that file.

Now, execute the command to change the permission 777.

sudo chmod 777 /path/to/directory/location

In the above Image I am changing the htdocs directory  permission to 777.  The number 777 means  that now anyone can upload  files to that directory .

d) Upload or modify files

After, you have changed the permission to 777, now it is time to upload or modify that file or directory.

In the above image I am trying to modify wp-config.php using Filezilla SFTP FTP client.

e) Change the file or directory permission to default permission

Now change the file or directory to its default permission. It will close the security hole, which you created by changing it permission to all(777).

Execute the below command,

sudo chmod default-permission-number /path/to/location

Warning: If you use “-R” with chmod command it will change all the files to 777 in  a directory.  Don’t use it if you don’t have an idea about WordPress file and folder permission structure.

4th Solution : Login as bitnami (For bitnami WordPress user)

This trick only work on bitnami WordPress. On bitnami WordPress  all the file under /opt/bitnami is owned by bitnami, so if you use bitnami as  user name while login via sftp or ftp, you can avoid the error.

a) Use bitnami as username while creating ssh keys

Create an RSA SSH key pair using puttygen and type bitnami in the Key comment section. If you don’t know how to create ssh key pair, then follow the tutorial in the link.

b) Connect to sftp using bitnami user name

Now, add the public key to your VM instances Metadata or SSH key section. If you don’t know how to does it then follow the link. 

After that open you SFTP ftp client and connect to google VM using ‘bitnami’ as user.

Now it is your time!

I tried my best to provide you a complete tutorial to fix permission denied error 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,

1 thought on “3 Ways to Solve Sftp or Ftp “Permission denied” on Google Cloud”

  1. Hi. I have checked your siteyaar.com and i see you’ve got some duplicate content so probably it
    is the reason that you don’t rank high in google.
    But you can fix this issue fast. There is a tool that rewrites articles like human, just search in google:
    miftolo’s tools

Leave a Comment

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