Shall I use `*` to chown all the files in one folder faster? - linux

I have 50+ scripts in folder cron-scripts, I only want exec them with cron shell only by root privileges.
# cd /var/www/html/cron-scripts/
# chown root:root scripts1.php
# chown fishman:users scripts1.php
# chown root:root scripts2.php
# chown fishman:users scripts2.php
Shall I use * to instead above code with the same effect?
# cd /var/www/html/cron-scripts/
# chown root:root *
# chown fishman:users *
And how to remove the root privileges if I have made chown root:root other-script.php?
I mean I want make this script open to all the public. (chown all-users:users other-script.php) thanks.

If you want to make a file readable by "others", you better use chmod with the parameters o+r which means "add read access for anyone else".
chmod o+r foo.bar

If you wanted to apply chown to all files in a directory, you can use the recursive option chown -R user:group directory, instead of *

Related

How to change directory permissions like made with 'sudo mkdir' in linux

I created the directory with "mkdir" command, after that I need to change permissions as if I made it with "sudo mkdir".
I've searched for the chmod command, but it doesn't seem to be what I'm looking for.
Is it possible to do this with a single command in terminal?
you can use the chown command to change the owner and group of the directory, and the chmod command to set the permissions.
sudo chown root:root /path/to/directory && sudo chmod 755 /path/to/directory

User cannot create file linux

may I know a command for root to change the mode to make the user able to create files.
I tried multiple times but I can seem to solve it.
[root#master ~]# useradd -d /opt/hadoop hadoop
useradd: cannot create directory /opt/hadoop
What are the permissions on /opt/hadoop? If you created the directory manually as root then it's probably owned by root and the user has no access to it - you'd need to chown -R it to the correct ownership.
chmod 755 /opt
chown root /opt
chmod 755 /opt/hadoop
chown -R user:user /opt/hadoop

Why file may give more permission than its directory?

it is in this file:
https://github.com/nathanctung/UCLA-CS-136/blob/1a883e2a6d1014fb5b162b332c867f6b4ef1e461/Assignment%203/submit2-1415097320/part2/patch2.sh
#!/bin/bash
sudo mkdir /home/memo-users # create memo-users directory in /home
sudo groupadd memo-users # create memo-users group and give them ownership
sudo chgrp -R memo-users /home/memo-users
sudo chmod 755 /home/memo-users
# at this point, users can be added to memo-users group
# all users dealing with memos should be added
sudo mkdir /home/memo-users/memo # add the actual dir for storing memos
sudo chmod 775 /home/memo-users/memo
sudo chmod +t /home/memo-users/memo # sticky bit keeps files from arbitrarily deletion
sudo cp fixed.patch /usr/lib/cgi-bin/ # copy the patch over to memo.cgi's dir
cd /usr/lib/cgi-bin
sudo chmod -s memo.cgi # remove root-SUID from memo.cgi altogether
patch < fixed.patch # apply the patch! this may need sudo su - access
This script can prevent different user from change others' memo. But I don't really know in detail what he has done. I can't understand why he set 755 to /home/memo-users but set 775 to /home/memo-users/memo. Could you tell me the purpose and the result of this scipt?
[7 for owner][7 for same group][5 for everyone]
R - read
W - write
X - execute
5 = R(yes)-W(no)-X(yes)
you can visit this directory only if you have R and X permission
7 = R(yes)-W(yes)-X(yes)
you can write sth. inside this directory
Now, you are in the same group with memo-users. You have R&X, so that you can enter /home/memo-users but unable to modify anything in this folder, and you have RWX in /home/memo-users/memo, so you can write sth. in this directory.
You have R+X permision in /home/memo-users is the prerequisite to access /home/memo-users/memo , but you can edit in /home/memo-users/memo is invoked by this directory itself.
This logic is smooth as far as I concerned. You have no permission writing anything in /home, but you can write sth. in /home/you-name right

Enable write permission for directory in Linux

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.

Setting directory in Linux

Someone please advise how to set the directory to chown root:root and chmod 0600, so that everything in it was created or copy the same settings as configured directory? thank you
Your question is not that clear ... but I think that perhaps what you're looking for is recursive application to apply chown and chmod settings to all files in the directory. This can be done (in both cases) using the -R flag, for example:
chown -R root:root mydir/*
I think you are looking for chmod -R 0600 * and chown -R root:root *, but your question is not entirely clear.
I think you are looking for the -R (recursive) flag - you can use
chown -R root:root /your/directory/full/path
and
chmod -R 0600 /your/directory/full/path
If instead you're copying an existing directory and want to retain permissions you can use
cp -a /current/path /new/path
and the -a flag will keep ownership and permissions the same
I think I understand your question now: you're trying to set the default permissions and ownership for new files in the directory.
For ownership, if you add yourself to the group that owns the directory (root in this case), then new files you create will be owned by that group.
For permissions, you can set default permissions for new files using umask:
umask 077 # grant only user r/w permissions
or using setfacl: see this answer for more information.

Resources