I've been using cp -r to duplicate some things in my file system and something bizarre keeps happening...certain directories that are permissioned as 777 have more secure permissions in the target directories I am copying to.
Is this normal behavior?
cp -a might resolve your situation, you need to tell cp to preserve the permissions so that it doesn't inherit them from your umask.
Related
I've just started to learn Linux Command Line. The setup I am on is AWS Lightsail bitnami Wordpress. I work with wordpress primarily.
I'm still confused about file permissions in Linux. Why do I have permissions denied when I sign in as the owner?
Whenever I have to ftp, overwrite, edit files and folders, I have to change the permissions settings for each affected folders and files manually via SSH.
More often than not, at the end of the day, I lost track of which folders and files' permissions I have edited and need to reset to default. I find this a chore and I believe there is a better way.
I wonder if there are lines of command that can
give me full access to all directories, folders, subfolders and files at once?
change the permissions for directories, folders, subfolders and files at once?
reset the permissions of all edited files to default/original all at once?
To check the permission of the file
sudo stat TARGETFOLDER
To change the permission of the file
sudo chmod 777 TARGETFOLDER
Bitnami Engineer here,
We configure the permissions of the WordPress' files by setting bitnami as the user owner and daemon as group owner of the files. This configuration allows you edit the files using the bitnami user and the webserver can use the daemon group to do the same. However, if you make changes to the application using the web interface (install plugins or themes), those new files are owned by daemon:daemon (the Apache and PHP-FPM services use that user and group so they generate the files using those permissions configuration) and you won't be able to edit them unless you use the command line and sudo. In that case, you can run the following commands to be able to edit those files using the bitnami user
sudo chown -R /opt/bitnami/apps/wordpress/htdocs
sudo find /opt/bitnami/apps/wordpress/htdocs -type d -exec chmod 775 {} \;
sudo find /opt/bitnami/apps/wordpress/htdocs -type f -exec chmod 664 {} \;
sudo chmod 640 /opt/bitnami/apps/wordpress/htdocs/wp-config.php
You can learn more about this here
https://www.youtube.com/watch?list=PLGgVZHi3XQNn4x0DU7Qj1r_inej3xEUda&v=nKfle7O0vN8&feature=emb_title
1 and 2, you can try chmod -R option.
3. i think it can not. you should restore it. maybe it help.
My goal is to prevent modify/read permission of other users except the owner. On ubuntu forums as solutions both approach is given.
sudo useradd -d /home/newuser -m newuser
chmod 700 /home/newuser # or # chmod go-rwx /home/newuser
[Q] Is there any difference between chmod go-rwx and chmod 700 or both accomplish the same thing? If there is a difference which one is recommended?
go-rwx removes read, write, execute permissions from the group and other users. It will not change permissions for the user that owns the file.
Therefore e.g. a file with 644 (rw-r--r--) permissions will have 600 (rw------) after the command.
chmod 700 on the other hand will always change the permissions to 700 (rwx------), no matter the previous permissions.
So it depends on what you want to accomplish.
Notes:
Especially when using -R to change entire directories, this makes go-rwx more useful, as the executable flag is usually only wanted on folders (so they can be entered) and program files that need to be executed.
Using 700 would add the executable flag to all files that don't have it yet, which is usually not what you'd want to do.
What the general effect of chmod 700 would actually look like in the other notation is chmod u+rwx,go-rwx or chmod u=rwx,go= (grants all permissions to user that owns file, removes all permissions of group and other)
Not all versions of chmod support the ugo±rwx syntax scheme.
There could be a difference:
chmod 700 lets the owner read , write and execute, and gives no permissions for Group and Other.
chmod go-rwx removes read/write/execute permissions from group and others, but preserves whatever permissions the owner had.
So, for example, if the owner didn't have execute permission on the file, to begin with, and only had read and write, the result could be different. With chmod 700, the owner would also get execute permission, which he would not with chmod go-rwx.
What is the difference of cp -p and cp -a in UNIX?
Hi Everyone, by seeing the subject you'll have an idea what I wanted to know but before that, if you know any emulator or site where I can put in my command to test please let me know so I can do it first on my own. I would like a UNIX test environment given the fact that I don't have a UNIX environment setup on my laptop. Thank you!
With the -p option, the copy has the same modification time, the same access time, and the same permissions as the original. It also has the same owner and group as the original, if the user doing the copy has the permission to create such files.
The -a option means -R and -p, plus a few other preservation options. It attempts to make a copy that's as close to the original as possible: same directory tree, same file types, same contents, same metadata (times, permissions, extended attributes, etc.).
I'm running a CentOS 5.0 server with root access. The /var/www folder was originally set recursively with root as the owner and group. So I did a chgrp -R webdevs /var/www and a chmod -R g+rwx /var/www command to give all members of the webdevs group read/write access. These changes work as required for all preexisting files. However, when user examplewebdev creates a new file in the /var/www directory, the group defaults to examplewebdev instead of webdevs. How do I change the defaults for new file creation?
Try to play with ACLs: man setfacl.
http://www.vanemery.com/Linux/ACL/linux-acl.html#default
I use 'newgrp' command but I think it applies only in the shell you are currently in.
I am a newbie in php, mysql. I have written a hello.php script, which I am trying to copy into /var/www directory (and will later want to open it through web browser). The problem with the same is that I am not allowed to save/write any files in /var/www despite me being the root. I tried implementing steps in this question, but I get the following error when I process the third line
find /var/www/ -type f -exec chmod g+w '{}' ';'
chmod: changing permissions of `/var/www/index.html': Operation not permitted
I know symlink is also an option. I would want to be able to write/copy files directly to /var/www/ directory.
Any suggestions on what is going wrong?
it'matter of *unix permissions, gain root acces, for example by typing
sudo su
[then type your password]
and try to do what you have to do
Do you have a file in /var/www called hello.php already that has permissions on it? Maybe the system can't replace the file?
Although, root access should supersede any user on the system.
Have you tried applying permissions to the www folder?
If you can do this, try the following:
sudo chmod -R 777 /var/www
then do:
sudo cp hello.php /var/www
I only recommend doing this if you know 100% that it is ok to set permissions on the whole www folder. By the sounds of it, you are running on your own production server as most live/shared hosting servers are setup so that the www folder is not in the /var folder (instead it is in the home folder of the user).
Be VERY careful when doing anything with the sudo prefix though, you can seriously damage your system if you do it wrong.
Are you in a development environment ? If Yes, You can do
chown -R user:group /var/www
so you will be able to write with your user.
Execute the following command
sudo setfacl -R -m u:<user_name>:rwx /var/www
It will change the permissions of html directory so that you can upload, download and delete the files or directories
Encountered a similar problem today. Did not see my fix listed here, so I thought I'd share.
Root could not erase a file.
I did my research. Turns out there's something called an immutable bit.
# lsattr /path/file
----i-------- /path/file
#
This bit being configured prevents even root from modifying/removing it.
To remove this I did:
# chattr -i /path/file
After that I could rm the file.
In reverse, it's a neat trick to know if you have something you want to keep from being gone.
:)
sudo chown -R $USER:$USER /var/www
First off, this has nothing to do with php. This is a unix permission issue. You need to login as a superuser ( sudo/su ) and type your password, then try that command.
$ su
(type password )
\# your command
$ sudo command
$ (type password)
It might also help if you actually specified the operating system you use.
sudo cp hello.php /var/www/
What output do you get?
If none of the above works, you might be dealing with a vfat filesystem. Use "df" to check.
See http://www.charlesmerriam.com/blog/2009/12/operation-not-permitted-and-the-fat-32-system/ for more details.
First of all, you need to login as root and than go to /etc directory and execute some commands which are given below.
[root#localhost~]# cd /etc
[root#localhost /etc]# vi sudoers
and enter this line at the end
kundan ALL=NOPASSWD: ALL
where kundan is the username and than save it. and then try to transfer the file and add sudo as a prefix to the command you want to execute:
sudo cp hello.txt /home/rahul/program/
where rahul is the second user in the same server.
You just have to write sudo instead of su.
Then just copy the PHP file to the var/www/ directory.
Then go to the browser, and write local host/test.php or whatever the .php filename is.
Enter the following command in the directory you want to modify the right:
for example the directory: /var/www/html
sudo setfacl -m g:username:rwx . #-> for file
sudo setfacl -d -m g:username: rwx . #-> for directory
This will solve the problem.
Replace username with your username.
The problem is a privilege issue navigate to the var/www/
right-click in it and select open as admin
then continue your work