How to access to a folder create with sudo ?

Change Ownership

sudo chown -R username:groupname /var/www/myfolder

Change Permissions:

sudo chmod -R 755 /var/www/myfolder

Accessing a folder created with sudo depends on the permissions set for that folder. If the folder's permissions do not allow your current user to access it, you will need to change the permissions or access it using sudo. Here are the steps to access such a folder:

1. Check Current Permissions

First, check the current permissions of the folder:

ls -ld /path/to/folder

This will show you the permissions, owner, and group of the folder. For example:

drwxr-xr-x 2 root root 4096 Jun 17 12:34 /path/to/folder

2. Access with sudo

If you need to access the folder with sudo (e.g., to list its contents):

sudo ls /path/to/folder

If you need to perform other actions like editing a file within the folder:

sudo nano /path/to/folder/file.txt

3. Change Permissions or Ownership

To make the folder accessible to your user, you can change the ownership or permissions.

Change Ownership

To change the owner of the folder to your user:

sudo chown yourusername /path/to/folder

To change both the owner and group:

sudo chown yourusername:yourgroup /path/to/folder
Change Permissions

To change the permissions of the folder so that your user can read, write, or execute files within it:

sudo chmod 755 /path/to/folder

This sets the permissions so that the owner can read, write, and execute, and others can read and execute.


Assume the folder is /var/www/myfolder, and you want to give the user john full access:

  1. Change Ownership:
sudo chown john /var/www/myfolder

or to change both owner and group:

sudo chown john:john /var/www/myfolder
  1. Change Permissions:
sudo chmod 755 /var/www/myfolder

Recursive Changes

If you need to change ownership or permissions for the folder and all its contents recursively, add the -R flag:

  1. Recursive Ownership Change:
sudo chown -R john:john /var/www/myfolder
  1. Recursive Permissions Change:
sudo chmod -R 755 /var/www/myfolder


By changing the ownership and/or permissions of a folder created with sudo, you can access it as your regular user. Always be cautious with permissions, especially when using sudo, to avoid security risks.