1 post tagged with "linux"

View All Tags

How to Resolve "Permission Denied" Issues When SFTP File Uploading to a Bitnami Server

Access Denied warning with a locked padlock, error symbols, and malware icons—representing SFTP permission issues on a Bitnami server.

You're not alone if you've ever attempted to upload a file to your Bitnami server using SFTP and run into the dreaded Permission denied error. When the person you're connecting as lacks the required write rights for the target directory, this problem frequently occurs. To help you troubleshoot and resolve this issue so you may resume your job, here is a simple instruction.

Recognizing the Issue#

Usually, the error looks something like this:

/path/to/target/directory/yourfile.ext" is the remote open function. Denied permission

This occurs because your SFTP account lacks write permissions to the directory you're attempting to upload to, which is held by a user (or group). This is particularly typical for WordPress or other application-related folders on Bitnami servers.

First step: Verify Permissions#

Illustration of a person entering an OTP code for two-factor authentication, representing secure login verification with a shield icon for data protection.

Go to the target directory first by SSHing into your server. To check its permissions, use the ls -ld command:

ssh -i LightsailDefaultKey.pem bitnami@yourserver
ls -ld /path/to/your/directory

This is what you'll see:

drwxr-xr-x 2 root root 4096 Nov 9 12:00 ai1wm-backups

In this instance, root is the owner of the directory, and only the owner is able to write. Your upload failed because of this.

Learn more about Linux file permissions

Second Step: Modify Permissions Temporarily#

You can let anyone write to the directory if you don't mind temporarily lowering the directory permissions:

sudo chmod 777 /path/to/your/directory

Next, use SFTP to upload your file:

sftp -i LightsailDefaultKey.pem bitnami@yourserver
cd /path/to/your/directory
put yourfile.ext

Revert the permissions to a more secure level after the upload is finished:

sudo chmod 755 /path/to/your/directory

More details on chmod

Step 3: Use scp with sudo#

Illustration of a person sitting with a laptop in front of a large screen showing a software update in progress, with cloud upload and refresh icons representing system updates and synchronization.

Another choice if you don't want to change the directory permissions is to upload the file to a temporary directory, such as /tmp, using scp (secure copy), and then use sudo to move it to the target directory.

Transfer the file to /tmp:#

scp -i LightsailDefaultKey.pem yourfile.ext bitnami@yourserver:/tmp

Move the file to the target directory:#

ssh -i LightsailDefaultKey.pem bitnami@yourserver
sudo mv /tmp/yourfile.ext /path/to/your/directory/

Best Practices#

  • Use the Least Privileges Required: To avoid security issues, always reverse directory permissions after finishing an operation.

  • Verify Control: If this is a routine task, think about giving the Bitnami user control of the directory:

    sudo chown bitnami:bitnami /path/to/your/directory
  • Automate Using Scripts: If you frequently perform this task, a straightforward script can help you save time and effort.

Bitnami Documentation has additional guidance on managing permissions effectively.

Conclusion#

That's it! You may easily upload your files and get around the Permission denied problem by changing permissions or by utilizing scp with sudo. This technique is applicable to any Linux-based system with comparable permission problems, not just Bitnami servers.

If you're looking for cloud deployment, check out what Oikos by Nife has to offer.