Halloween DealsAmazon USHalloween week deals: useful picks before month-endAmazon US: current deals, useful picks and tech finds.Check DealsPC HealthRecommendedCrashes, freezes, slowdowns? Check your PC nowSpot repairable issues before they interrupt work.Check PCHalloween DealsAmazon USOctober picks are moving - compare before checkoutAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk10 min

How to Fix “Permission Denied” Errors When Uploading Files to a VPS

SSH access does not automatically grant write access. This guide shows how to trace the exact account and path, repair permissions safely, verify the result, and choose scp, SFTP, or rsync for VPS deployments.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

A successful SSH login proves that the server accepted your identity; it does not prove that your account can write to the destination. To fix an upload error, check the exact remote user, every directory in the path, and the policy controlling ownership, groups, ACLs, mounts, and security contexts. Then test a write as that same account.

For a safe long-term repair, upload to a user-owned staging directory or grant a deployment group or ACL only the access the release process needs. Do not make a web root universally writable with chmod -R 777.

As an Amazon Associate I earn from qualifying purchases.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Start with the exact account and path

“Permission denied” can describe several different failures. A transfer may be rejected before a remote shell starts, or the SSH session may work while the filesystem refuses a create, replace, rename, or directory traversal operation. Diagnose the operation that failed rather than changing permissions blindly.

Run this from a shell that can connect to the VPS, replacing the account, host, and path with the values from your transfer command:

#1 Best Overall
Sale
Lexar D40E 128GB Dual USB 3.2 Gen 1 Type-C Jump Drive, Champagne Silver | USB-C Flash, Metal Housing, Swivel Design, Thumb Drive
  • USB-C 2-in-1 storage OTG: The Lexar JumpDrive Dual Drive D40E features USB Type-A and Type-C connectors in a slim, portable form factor for easy device compatibility
  • Transfer speeds up to 100MB/s: Based on internal testing, performance may vary depending upon the host device, interface, and usage conditions. 1MB=1,000,000 bytes
  • Plug and Play: Widely compatible with USB Type-C smartphones, tablets, laptops, Macs, and traditional Type-A devices, no software installation required. The 360° swivel design allows for easy switching between connectors without the hassle of losing a cap
  • Durable & Compact: The Lexar D40E USB memory stick features a metal enclosure, withstands temperatures from 0° to 50° C (32°F to 122°F), and is lightweight at 26g with dimensions of 70.4 x 16.9 x 11.7mm
  • Security & Warranty: Securely protects files using an advanced security software solution with 256-bit AES encryption. Backed by a Lexar 3-year limited warranty
ssh user@host 'id; namei -l /var/www/site/file.txt; ls -ld /var/www /var/www/site'

The command prints the effective user and groups, then shows permissions on every component of the path. If the destination file does not exist, namei still helps identify a parent directory that cannot be traversed.

What the output tells you

  • id confirms which account and groups the server is actually using. A local username or a different SSH key does not change the remote account.
  • namei -l reveals permissions and ownership for each parent directory. The account needs execute (traverse) permission on every directory between the root and the target.
  • ls -ld shows the final directory’s owner, group, and mode. Creating a new entry requires write and execute permission on that directory; replacing or renaming an existing entry also depends on the containing directory.

A file’s mode alone is therefore not enough. A file can be writable while an ancestor directory blocks access, and a directory can be readable while denying creation because it lacks write permission.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Separate SSH authentication from filesystem authorization

SSH authentication answers “may this key and username start a session?” Filesystem authorization answers “may this account perform this operation on this path?” The first can succeed while the second fails.

When the error is Permission denied (publickey)

If the message mentions publickey, appears before a remote shell starts, or occurs while opening the SSH connection, inspect the connection rather than the web directory. Verify the username, host, port, and identity file:

ssh -i ~/.ssh/deploy_key -p 22 deploy@host 'id'

The OpenSSH client uses -i to select an identity file. On the client, the private key should normally be readable only by its owner, and the SSH directory should not be writable by other users:

chmod 700 ~/.ssh
chmod 600 ~/.ssh/deploy_key
chown -R "$USER:$USER" ~/.ssh

Oracle’s OpenSSH guidance notes that incorrect permissions in directories on either side of the connection can cause a Permission Denied error. Correcting key and .ssh ownership addresses authentication; it does not grant write access under /var/www.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

When SSH works but scp or SFTP cannot write

Run the diagnostic command through the same account used by the transfer. If ssh deploy@host 'id' works but scp file deploy@host:/var/www/site/ fails, the likely issue is remote path authorization, a read-only filesystem, a chroot or forced command, or a service that changes permissions after upload.

Rank #2
SANDISK 128GB Ultra Flair, USB-A Flash Drive, Up to 150MB/s Read Speeds | USB Flash Drive, Up to 15x Faster than standard 2.0, Password Protection, Durable, Sleek Metal Casing, USB 3.0, Silver/Black
  • High-speed USB 3.0 performance of up to 150MB/s(1) [(1) Write to drive up to 15x faster than standard USB 2.0 drives (4MB/s); varies by drive capacity. Up to 150MB/s read speed. USB 3.0 port required. Based on internal testing; performance may be lower depending on host device, usage conditions, and other factors; 1MB=1,000,000 bytes]
  • Transfer a full-length movie in less than 30 seconds(2) [(2) Based on 1.2GB MPEG-4 video transfer with USB 3.0 host device. Results may vary based on host device, file attributes and other factors]
  • Transfer to drive up to 15 times faster than standard USB 2.0 drives(1)
  • Sleek, durable metal casing
  • Easy-to-use password protection for your private files(3) [(3)Password protection uses 128-bit AES encryption and is supported by Windows 7, Windows 8, Windows 10, and Mac OS X v10.9 plus; Software download required for Mac, visit the SanDisk SecureAccess support page]

Understand the permissions required for an upload

For a new file, the destination directory must permit the account (or an applicable group or ACL) to write and traverse. For an existing file, the operation may require write permission on the file, its parent directory, or both, depending on whether the client truncates, replaces, renames, or creates a temporary file.

Directory traversal is required at every level

Consider /var/www/site/assets/app.css. The account must be able to traverse /var, /var/www, /var/www/site, and any intervening directory. A missing execute bit on one parent produces “permission denied” even if app.css is mode 664.

Creation, replacement, and rename are different operations

  • Creating new.css needs write and execute permission on the containing directory.
  • Overwriting an existing file may need write permission on that file and its directory.
  • Atomic deployment tools commonly upload a temporary file and rename it. The rename is controlled by the source and destination directories, so a directory that permits ordinary writes may still reject the final move.

Check the precise destination in the client command. A trailing slash can make a client treat a path as a directory, while a filename can request replacement of an existing entry.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Safe repair pattern 1: upload to a staging directory

A user-owned staging directory is the simplest least-privilege design. The transfer account writes only to its home directory; a controlled release step then copies or moves validated files into the service tree.

  1. Log in as an administrator or an account allowed to create the deployment directory.
  2. Create and assign the staging path:
sudo mkdir -p /home/deploy/releases/site
sudo chown -R deploy:deploy /home/deploy/releases
sudo chmod 750 /home/deploy /home/deploy/releases /home/deploy/releases/site
  1. Upload to the staging path:
scp -i ~/.ssh/deploy_key ./site.tar.gz deploy@host:/home/deploy/releases/site/
  1. Perform a server-side release step as an account authorized to update the service directory. For an archive, extract into a new release directory, set the intended owner and mode, and switch the service’s release link or path according to your deployment design.
  2. Keep the staging directory outside the web-served tree unless you deliberately need it served. Remove failed or obsolete releases according to your retention policy.

This pattern avoids granting an upload account broad write access to configuration files, package-managed content, or the entire web root.

Safe repair pattern 2: use a shared deployment group

Use a group when several administrators or automation accounts must update the same site tree. The web service account can retain read access while the deployment group receives only the write access required.

  1. Create a dedicated group and add the deployment account:
sudo groupadd webdeploy
sudo usermod -aG webdeploy deploy

The account must start a new login session before its supplementary group list reflects the change.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #3
2 Pack 64GB USB Flash Drive USB 2.0 Thumb Drives Jump Drive Fold Storage Memory Stick Swivel Design - Black
  • What You Get - 2 pack 64GB genuine USB 2.0 flash drives, 12-month warranty and lifetime friendly customer service
  • Great for All Ages and Purposes – the thumb drives are suitable for storing digital data for school, business or daily usage. Apply to data storage of music, photos, movies and other files
  • Easy to Use - Plug and play USB memory stick, no need to install any software. Support Windows 7 / 8 / 10 / Vista / XP / Unix / 2000 / ME / NT Linux and Mac OS, compatible with USB 2.0 and 1.1 ports
  • Convenient Design - 360°metal swivel cap with matt surface and ring designed zip drive can protect USB connector, avoid to leave your fingerprint and easily attach to your key chain to avoid from losing and for easy carrying
  • Brand Yourself - Brand the flash drive with your company's name and provide company's overview, policies, etc. to the newly joined employees or your customers
  1. Assign the site directory to the group:
sudo chown -R root:webdeploy /var/www/site
sudo find /var/www/site -type d -exec chmod 2775 {} +
sudo find /var/www/site -type f -exec chmod 0664 {} +

The leading 2 on directory mode sets the setgid bit, causing newly created entries to inherit the directory’s group. File and directory modes should be adjusted to your application’s needs; executable files, private configuration, and upload directories may require different modes.

  1. Confirm that the web service can still read the tree and that deployment members can create and replace the intended files.

Setgid does not make every future file writable by every group member if a restrictive umask removes group write permission. Default ACLs can enforce the desired inherited permissions when a group design alone is insufficient.

Safe repair pattern 3: grant a narrowly scoped ACL

An access control list is useful when the deploy account needs access but changing the directory’s owning group would affect other users or services. First inspect existing ACLs:

getfacl /var/www/site

Grant the account traversal and the directory permissions it actually needs. For example, to allow deploy to work in a site directory:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
sudo setfacl -m u:deploy:rwx /var/www/site

If the account must create files in nested directories, apply an intentional ACL to those directories or configure default ACLs for new entries. Then inspect the result with getfacl; the effective permission can be reduced by a mask entry. ACLs should be documented because ordinary ls -l output may show a trailing plus sign without explaining the full policy.

Change ownership only when it matches the service design

Changing ownership can be correct for a tree deliberately managed by the deployment account:

sudo chown -R deploy:web /var/www/site

It is dangerous as a reflex. A recursive ownership change can make a web server unable to read files, alter package-managed files, expose secrets to a deployment user, or conflict with a container bind mount. Before using chown -R, decide which account should own source files, which account should run the service, and whether configuration and runtime-generated data belong in separate directories.

Rank #4
Sale
SIMMAX 32GB Memory Stick USB 2.0 Flash Drives Swivel Thumb Drive Pen Drive (32GB Purple)
  • GOOD VALUE PACKAGE - 1 Pack 32GB Memory Stick USB 2.0 Flash Drives with great cost performance and high quality.
  • BIG CAPACITY - The available capacity: 29.10GB-29.8GB, You can save the data of movies, music, photos, designs, programs, manuals, handouts in a high speed.Good performance in digital data storing, transferring and sharing with families, friends, workmates, clients and machines.
  • EASY TO USE & PLUG AND WORK - Support windows 7 / 8 / 10 / Vista / XP / 2000 / ME / NT Linux and Mac OS, Compatible with USB2.0 and below.
  • TWISTTURN DESIGN & EASY CARRY - The metal clip rotates 360° round the ABS plastic body which with rubber oil skin feeling finish. The capless design can avoid lossing of cap, and providing efficient protection to the USB port.
  • WARRANTY & SUPPORT - SIMMAX logo is laser printed on the USB connector surface, our products are of good quality and we promise that any problem about the product within one year since you buy.

Verify the repair as the transfer account

Do not validate only as root or as your administrative account. Test the same identity used by scp, SFTP, or rsync:

sudo -u deploy test -w /var/www/site && echo writable
sudo -u deploy touch /var/www/site/.permission-test
sudo -u deploy rm /var/www/site/.permission-test

The first command checks whether the directory is considered writable. The create-and-remove test verifies the actual operation and leaves no test file when successful. If your deployment replaces files through a temporary name, test creation, rename, and deletion in the same directory rather than testing only an existing file.

Choose the transfer tool for the job

Tool Best fit Useful capabilities Important permission behavior
scp One-off file or archive copy Simple command-line transfer; accepts an identity file with -i and destinations such as user@host:/remote/path/ Needs write and traversal access to the remote destination; it does not solve ownership policy.
SFTP Interactive inspection and transfer put, put -R, ls -l, chmod, chown, and df where the server supports the relevant extensions Useful for identifying the directory that fails. put -p preserves permissions and access times when supported, which can conflict with destination policy.
rsync Repeatable folder synchronization over SSH Efficient incremental copies; can preserve links, devices, owners, groups, and permissions when requested Rsync must be installed on both ends for remote transfers. Destination umask and default ACLs affect newly created files.

A conservative rsync command

When the server’s ownership and mode policy should remain authoritative, avoid copying local metadata:

rsync -az --no-perms --no-owner --no-group ./site/ deploy@host:/home/deploy/releases/site/

After synchronization, run the server-side release step that sets the service’s intended owner and mode. If you do need controlled permissions during transfer, rsync’s --chmod option can set modes explicitly, but it does not override directory ownership, ACLs, read-only mounts, or security policies.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Check the less obvious causes

If ownership, modes, and group membership look correct, continue with the controls below.

ACLs

An ACL can allow or deny an account independently of the traditional owner/group/other bits. Run getfacl on every relevant parent and the destination directory. Look for a restrictive ACL mask or an explicit deny in the system’s access-control model.

SELinux or another mandatory access-control system

On systems using SELinux, inspect the security context:

Best Value
IMEASON Swivel Design 16GB USB Flash Drive with Keychain, USB 2.0 Portable Thumb Drive Memory Stick, FAT32 Format Flashdrive for Data Storage, Photos, Music, Files (Black, 16 GB)
  • 【16GB Flash Drive】USB flash drives with 16GB capacity, meet your needs of daily use on work, school, home and travelling for photos, music, videos, files storage and transfer. IMEASON thumb drives can be used to store different files, easy to data backup.
  • 【Metal Swivel Cap Design】USB thumb drive is metal swivel cover provides extra protection for the usb thumbdrive connector, no usb drive cap to lose; keychain design makes it easier to carry without worrying lose it.
  • 【Wide Compatibility】USB drive supports Windows 7/8/10/11 / Vista / XP / Unix / 2000 / ME / NT Linux and Mac OS, also Supports USB 2.0 and 1.1 ports. USB Stick support TV, desktop, notebook computer, car, audio and other device. The USB Memory Stick is your great data storage and transfer companion with traveling and working.
  • 【Easy to use】usb memory stick is plug and play without any software installation. Just simply plug the Flashdrive into the port of your USB-compatible devices such as computer, laptop to start data storage or transmission.
  • 【What You Get】16 GB USB Flash Drive Thumb Drive, The default format of the usb storage flash drive is FAT32.
ls -Zd /var/www/site

A Unix mode that appears writable may still be denied by the context. Use the distribution’s audit logs and policy tools to identify the denial; do not disable SELinux merely to make an upload work. The correct context for web content differs from the context for user home files and writable application data.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Read-only mounts

A filesystem mounted read-only rejects writes for every user, including root in many situations. Check the mount options:

findmnt -no TARGET,OPTIONS /var/www

If the output includes ro, investigate why the mount is read-only before changing file permissions. A failed disk, an intentional immutable deployment, or a container volume policy may be responsible.

Full disk or inode exhaustion

A filesystem can have free bytes but no inodes, preventing new files. Check both:

df -h /var/www
df -i /var/www

Free space or inodes according to the system’s retention and logging policy. Deleting arbitrary files from a live service can cause data loss.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

SFTP chroot, forced commands, and subsystem rules

An SFTP-only account may be confined to a chroot and unable to address the path you see from an ordinary shell. An SSH ForceCommand can replace the requested command, and a server’s SFTP subsystem configuration can limit operations. Compare an interactive SSH session with the SFTP account’s visible root and inspect the effective SSH server configuration as an administrator.

Containers and bind mounts

A path such as /var/www/site may be a bind mount owned by a UID or GID that differs from the host account names. Check the container or orchestration configuration, numeric IDs, and mount mode. Changing host ownership can break the container’s service user or be overwritten when the container is recreated.

Permission-rewriting deployment services

A post-upload hook, extraction job, package update, or web application may reset ownership and modes immediately after transfer. Watch the directory after a successful test and inspect deployment logs. If permissions change back, fix the responsible job or its release policy instead of repeatedly applying manual chmod.

Common mistakes and their safer alternatives

  • Uploading directly to /var/www as an ordinary user: use a staging directory or a documented deployment group.
  • Running chmod -R 777: grant the required owner, group, or ACL permissions and retain restrictive modes for secrets.
  • Testing only with sudo: use sudo -u deploy so the test matches the transfer account.
  • Copying local ownership and modes with rsync: use --no-perms --no-owner --no-group when the destination policy should win.
  • Assuming an existing file’s mode controls replacement: verify the containing directory, temporary-file creation, and rename permissions.
  • Changing ownership recursively without a service plan: separate deploy, web-service, configuration, and runtime-data ownership before modifying the tree.

A practical decision path

  1. If the error is Permission denied (publickey), correct the username, key, host, port, and local SSH permissions.
  2. If SSH login succeeds, run id, namei -l, and ls -ld on the exact destination.
  3. Check traversal on every parent and write/execute permission on the destination directory.
  4. Choose staging, a shared group, or a narrowly scoped ACL rather than opening the directory to everyone.
  5. Test create, replace, rename, and delete as the transfer account.
  6. If the test still fails, inspect ACLs, SELinux contexts, mount options, disk and inode capacity, SFTP restrictions, containers, and permission-rewriting services.
  7. Select scp for a simple one-off copy, SFTP for interactive diagnosis, or rsync for repeatable synchronization.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Leave a Reply

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

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Windows Errors? Fix Them Before They SpreadFree repair scan
Outdated Drivers Are Slowing You DownFree scan - exact matches

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.