Report this

What is the reason for this report?

How to grant new user permission to files/folders under /var/WEBSITE directory

Posted on January 31, 2018

Im new to linux. I have a root account and a regular account. The droplet is currently in production so i dont want to take the server unintentionally. How do I grant my new non-sudo user to be able to upload files via SFTP to folder structure under /var/website_files



This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

To modify the permissions for a specific directory so that you can write to it, set read/write permissions with the command below

sudo chmod 766 -R /var/www/html

This will assign full permissions 7 for the owner, read/write 6 for the group, and read/write for everyone 6, recursively.

To grant a new user permission to access and manipulate files or folders under the /var/WEBSITE directory, you can modify the ownership and permissions of the directory using various methods depending on your requirements. Below are the most common approaches:

1. Change Ownership of the Directory

  • You can change the ownership of the /var/WEBSITE directory and its contents to the new user.

Steps:

sudo chown -R username /var/WEBSITE
  • -R is used to apply the change recursively to all files and directories inside /var/WEBSITE.
  • Replace username with the actual username of the new user.

This method grants the new user full ownership of the directory and all its contents.

2. Add the User to a Group and Change Group Ownership

If you want to allow multiple users (e.g., web developers) to access the directory, you can create a group, assign the user to that group, and change the group ownership of the /var/WEBSITE directory.

Steps:

  1. Create a group (if it doesn’t already exist):
sudo groupadd webgroup
  1. Add the user to the group:
sudo usermod -aG webgroup username
    • Replace username with the actual user’s name.
    • The -aG option appends the user to the group without removing them from any existing groups.
  1. Change the group ownership of the directory:
sudo chown -R :webgroup /var/WEBSITE
  1. Set directory permissions: To ensure that group members can read and write to the directory, set the correct permissions:
sudo chmod -R 775 /var/WEBSITE
    • This grants read, write, and execute permissions to the owner and group, but only read and execute permissions to others.
  1. Set the setgid bit on the directory (optional but recommended): The setgid bit ensures that new files and directories created within /var/WEBSITE inherit the group of the parent directory (webgroup in this case), rather than the user’s primary group.
sudo chmod g+s /var/WEBSITE

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.