How to Check and Change Folder Permissions in Ubuntu Using SSH
If you’re managing an Ubuntu server, you’ll often need to check or change folder permissions. This is especially important when setting up a website, FTP/SFTP users, or troubleshooting “Permission denied” errors.
In this guide, you’ll learn how to:
- Check folder permissions
- Check file ownership
- Change permissions
- Change ownership
- Apply permissions recursively
- Troubleshoot common permission problems
Step 1: Connect to Your Server
Connect to your server using SSH:
ssh username@your-server-ip
Replace username with your server username and your-server-ip with your server’s IP address.
Step 2: Check Folder Permissions
To view the permissions on a folder, use:
ls -ld /path/to/folder
Example:
ls -ld /var/www/html
Example output:
drwxr-xr-x 5 www-data www-data 4096 Jul 16 20:15 /var/www/html
Understanding the Output
- d — Directory
- rwx — Owner permissions (Read, Write, Execute)
- r-x — Group permissions (Read and Execute)
- r-x — Other users’ permissions (Read and Execute)
The next two fields show the owner and group of the directory.
Step 3: Check Folder Ownership
To see who owns a directory:
stat /path/to/folder
Example:
stat /var/www/html
Example output:
Owner: www-data
Group: www-data
You can also list files with ownership information:
ls -l
Step 4: Change Folder Permissions
Use the chmod command to change permissions.
Give the owner full access
chmod 755 /path/to/folder
Permission breakdown:
- Owner: Read, Write, Execute
- Group: Read, Execute
- Others: Read, Execute
Give the owner and group full access
chmod 775 /path/to/folder
Permission breakdown:
- Owner: Read, Write, Execute
- Group: Read, Write, Execute
- Others: Read, Execute
Give everyone full access (Not Recommended)
chmod 777 /path/to/folder
⚠️ Warning: Avoid using 777 on production servers. It allows anyone to modify the folder and can create serious security risks.
Step 5: Change Folder Ownership
If another user needs control of a directory, use chown.
Example:
sudo chown ftpuser:ftpuser /path/to/folder
This changes both the owner and group to ftpuser.
Step 6: Change Ownership Recursively
To change ownership of a folder and everything inside it:
sudo chown -R ftpuser:ftpuser /path/to/folder
The -R option applies the change to all files and subfolders.
Step 7: Change Permissions Recursively
Apply permissions to an entire directory tree:
chmod -R 755 /path/to/folder
Or, if group members also need write access:
chmod -R 775 /path/to/folder
Step 8: Check Your Current User
To see which user you’re logged in as:
whoami
To view your user ID and group memberships:
id
Example output:
uid=1001(ftpuser) gid=1001(ftpuser) groups=1001(ftpuser),27(sudo)
Common Permission Values
| Permission | Meaning | Typical Use |
|---|---|---|
| 755 | Owner can read, write, execute; others can read and execute | Website folders |
| 775 | Owner and group can read, write, execute | Shared directories |
| 700 | Only the owner has access | Private directories |
| 644 | Owner can read/write; others can read | Website files |
| 600 | Only the owner can read/write | Sensitive files |
| 777 | Everyone has full access | Testing only (not recommended) |
Typical Web Server Permissions
For Apache or Nginx websites:
sudo chown -R www-data:www-data /var/www/html
sudo find /var/www/html -type d -exec chmod 755 {} \;
sudo find /var/www/html -type f -exec chmod 644 {} \;
This configuration allows the web server to access your website while keeping permissions secure.
Troubleshooting “Permission Denied”
If you receive a “Permission denied” error:
- Check the folder owner:
ls -ld /path/to/folder - Verify your current user:
whoami - Check your group memberships:
id - If needed, change ownership:
sudo chown -R username:username /path/to/folder - Update the permissions:
chmod -R 755 /path/to/folder
Conclusion
Understanding Linux file permissions is essential for managing websites, FTP/SFTP users, and applications on Ubuntu. Using ls, stat, chmod, and chown together allows you to quickly diagnose and fix most permission-related issues while keeping your server secure.
By following the steps in this guide, you’ll be able to confidently manage directory ownership and permissions from the command line.
