How can I transfer files from my Lightsail instance if I receive "permission denied" errors?

2 minute read

I get permission denied errors when I transfer files owned by the root user from my Amazon Lightsail instance.

Short description

To transfer files owned by the root user from your Lightsail instance, first copy the files to the home directory of the current user. Then, change the ownership of the files and give the new owner permission to copy the files. The permissions of the original file remain the same because this method copies a copy of the file.

Note: To copy the files, the user must be able to assume root permission. Or, the user must be in the sudoers file.


Note: The following example uses this directory:


The example file has the following permissions:

drwx------  3 root    root    4096 Aug 17 04:24 systemd-private-a244e4fc08504ae39236f514bdffecc1-chrony.service-AFB67v
  1. Connect to the Lightsail instance using SSH as your normal user. In this example, the user is bitnami.

  2. Run the cp command to copy the file to the home directory of the user.

    sudo cp -R  systemd-private-a244e4fc08504ae39236f514bdffecc1-chrony.service-AFB67v/ /home/bitnami/
    # ls -al /home/bitnami/systemd-private-a244e4fc08504ae39236f514bdffecc1-chrony.service-AFB67v/
    total 12
    drwx------ 3 root    root    4096 Aug 17 05:02 .
    drwxr-xr-x 4 bitnami bitnami 4096 Aug 17 05:02 ..
    drwxr-xr-t 2 root    root    4096 Aug 17 05:02 tmp

    Note: You can run the cp command with sudo. Or, you can change to the root user, and then run the command. Use the following command to change to the root user:

    sudo -i
  3. Change the ownership of the copied file:

    sudo chown bitnami:bitnami /home/bitnami/systemd-private-a244e4fc08504ae39236f514bdffecc1-chrony.service-AFB67v/ -R
  4. Transfer the copied directory or file. The following example transfers the file with Filezilla:

    Status:	Directory listing of "/home/bitnami" successful
    Status:	Using username "bitnami". 
    Status:	Connected to 3.xx.xx.1x2
    Status:	Starting download of /home/bitnami/systemd-private-a244e4fc08504ae39236f514bdffecc1-chrony.service-AFB67v/tmp/testing.txt
    Status:	File transfer successful, transferred 230,756 bytes in 1 second
AWS OFFICIALUpdated 2 months ago