I keep trying to move files from a directory on Linux- but I keep getting permission errors.
Initially I was told
sudo chmod -R r+w /directory/*
But this only applies it to the directory folder (and not the files inside)
Trick is- you need to "select all" to apply the file permissions to:
sudo chmod -R a+rwx,go-w /directory/
And that's it
Or you could do sudo chmod 777 /dir/
and that's just a simple way to do the answer stated above.
Related
I am new to linux. I have a build.sh file which consists of a lot of mkdir commands and some rm commands. But as I have installed this new in my VB, each time I run the .sh file, it says "Permission Denied for creating directory" and fails.
So is there any way that I grant directory privileges to all users.
Can anyone help me with this
Add "sudo" in the beginning of the directory creation command i.e
sudo mkdir dir_name
The issue might be with the directory in which the mkdir command is being run.
Use the command ll or ls -l to check the directory permissions.
If your directory doesn't have write privilege for the current user, you can run
chmod -R u+w /path/to/directory
This might require you to use sudo if permission is denied.
If you want to enable it for all users, run
chmod -R ugo+w /path/to/directory
Alternatively, a quick fix would be to run the build.sh file as root
sudo /path/to/build.sh
However, this approach is not advised unless you always run it as root
I am using Ubuntu windows 10 bash and I'd like to move a project from /mnt/i/Projects/Template to run it on Apache server which located in /var/www/html.
I tried to copy a folder from a direct to new directly but unfortunately I got an error which is:
cp -r /mnt/i/Projects/Template ~/var/www/html/
cp: target '/root/var/www/html/' is not a directory
I would like to test those templates with Apache and I tried to change Apache directly.
Another test I did:
root#DESKTOP-4PBGG1N:/var/www# ls -ld ~/var ~/var/www ~/var/www/html
ls: cannot access '/root/var': No such file or directory
ls: cannot access '/root/var/www': No such file or directory
ls: cannot access '/root/var/www/html': No such file or directory
First of all the directory for the apache server is not in root it's just "/var/www/html". If it still doesn't work you probably doesn't have apache installed, you can do that by running these two lines "lsb_release -a" and "sudo apt-get install apache2". There will come an error when trying to launch the apache server (with "sudo service apache2 start"), but just ignore it you can still use it without any problems. Hope it helps ;)
try creating directory if the only problem is '/root/var/www/html/' not being a directory
# mkdir -pv ~/var/www/html/
# cp -r /mnt/i/Projects/Template ~/var/www/html/
before that just make sure that apache is installed and configured
have a nice day
For instance you have a file in Documents called index.php and to be copied in the /root/var/www/html/ directory you have to do it this way:
First don't forget to use sudo to be super user and then
- sudo cp -Rv index.php /var/www/html or
- sudo cp -Rv index.php /root/var/www/html
And you will get this output: 'index.php' -> '/var/www/html/index.php'
-R for copy folders &
-v for see what folders and files are copied
I want my php script to be able to create file, edit, and delete it, so I need to give it permissions to do so in Linux.
I've done this with one of the stackoverflow answers with this code:
sudo chown -R www-data:www-data .
But when I do so, I lose my user access to files - so I can't open them with gedit for example until I change permissions back like so:
sudo chown -R igor /var/www/html/demo/myDir
I think I need to give permission to Apache, but leave my access as well. I feel there is some easy answer to make it work, but I can't find one. Any suggestions?
You are changing the owner of the files, if you want to change the permission of the files without changing the owner you need to use : chmod.
For example if you want to read write and execute on the current folder you can use: chmod 777 .
If what you want is the two users have the same permissions over the folder you could add your user to the group www-data (assuming that you are in the files folder):
sudo usermod -a -G www-data youruser
sudo chgrp -R www-data .
sudo chmod -R 770 .
A company mine is working with is having permissions issues for uploading files (via FTP). We found a workaround of putting everything to 777 (not my first choice, but ease of use trumps security here).
The problem with this is that Drupal breaks upon putting the root directory as 777.
Why is this? How can I change that?
Typically your files directory should be:
chmod -R 775 files
But also make sure your owner and group are correct. The owner in this case should be your ftp user. And your group should be the apache user.
chgrp -R apache_user files
chown -R ftp_user files
Having problem to upload files with ftp or with drupal? Drupal need write permission in sites/default/files to save images and css etc.
Maybe its problem with owner too?
Check this page: http://drupal.org/node/244924
The problem with this is that Drupal breaks upon putting the root
directory as 777.
Actually you need to change not root of Drupal directory but the directory sites/default/files.
If you want to do that in easiest way change this directory permissions to 777:
cd <your Drupal root>/sites/default
chmod -R 777 files
The secure way is to set your WWW user (e.g. www-data) as an owner of this directory:
cd <your Drupal root>/sites/default
chown -R www-data files
chmod -R 775 files
Also you can add your group (e.g. my_group):
chgrp -R my_group files
This question already has answers here:
How do I change permissions for a folder and its subfolders/files? [closed]
(19 answers)
Closed 4 years ago.
I have a web directory /www and a folder in that directory called store.
Within store are several files and folders. I want to give the folder store and all files and folders within the store folder all permissions.
How do I do this? I am guessing via .htaccess.
If you are going for a console command it would be:
chmod -R 777 /www/store. The -R (or --recursive) options make it recursive.
Or if you want to make all the files in the current directory have all permissions type:
chmod -R 777 ./
If you need more info about chmod command see: File permission
If by all permissions you mean 777
Navigate to folder and
chmod -R 777 .
You can give permission to folder and all its contents using option -R i.e Recursive permissions.
But I would suggest not to give 777 permission to all folder and it's all contents. You should give specific permission to each sub-folder in www directory folders.
Ideally, give 755 permission for security reasons to the web folder.
sudo chmod -R 755 /www/store
Each number has meaning in permission. Do not give full permission.
N Description ls binary
0 No permissions at all --- 000
1 Only execute --x 001
2 Only write -w- 010
3 Write and execute -wx 011
4 Only read r-- 100
5 Read and execute r-x 101
6 Read and write rw- 110
7 Read, write, and execute rwx 111
First Number 7 - Read, write, and execute for the user.
Second Number 5 - Read and execute for the group.
Third Number 5 - Read and execute for others.
If your production web folder has multiple users, then you can set permissions and user groups accordingly.
More info :
Understanding File Permissions: What Does “Chmod 777″ Mean?
What file permissions should I set on web root?
Why shouldn't /var/www have chmod 777
You can also use chmod 777 *
This will give permissions to all files currently in the folder and files added in the future without giving permissions to the directory itself.
NOTE: This should be done in the folder where the files are located. For me it was an images that had an issue so I went to my images folder and did this.
Yes, very right that the -R option in chmod command makes the files/sub-directories under the given directory will get 777 permission. But generally, it's not a good practice to give 777 to all files and dirs as it can lead to data insecurity. Try to be very specific on giving all rights to all files and directories. And to answer your question:
chmod -R 777 your_directory_name
... will work
for mac, should be a ‘superuser do’;
so first :
sudo -s
password:
and then
chmod -R 777 directory_path
This didn't work for me.
sudo chmod -R 777 /path/to/your/file/or/directory
I used -f also.
sudo chmod -R -f 777 /path/to/your/file/or/directory