User cannot create file linux - 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

Related

mongodb & /data/db directory permissions

I'm trying to run mongod with its defaults so it's using the /data/db directory. I changed the owner of the data directory
sudo chown mongodb:mongodb /data -R
Like so many others i got the following error when first running mongod.:
2017-04-11T12:32:25.932-0500 I STORAGE [initandlisten] exception in initAndListen: 28596 Unable to determine status of lock file in the data directory /data/db: boost::filesystem::status: Permission denied: "/data/db/mongod.lock", terminating
Which makes sense but what doesn't make sense is the only way i can actually run it mongod is if i:
chmod 777 /data -R
If i
chmod 666 /data -R
i get the same error. Since this is supposed to be the data directory why does it require execute permission.
i added my user to the mongodb group
sudo usermod -g mongodb myuser
and then i tried
chmod 770 /data -R
and its still failing even through i'm a member of the mongodb group.
Why am i messing with all this? Because i want to secure the data directory appropriately and don't want to have to run with 777 security.
So the questions are:
Why is execute permission required
Why am i unable to run it when i was a member of the mongodb group?
Directories need to have execute permission, but the files within the directories do not need execute permission. Also, as noted by #franklinsijo, -R should be the first parameter to chmod.
To fix things I would do the following:
$ sudo chmod -R 770 /data
$ sudo find /data -type f -exec chmod 660 {} \;
This will first give everything under /data execute permission, and then return all the normal files to having only read and write, but not execute.

Change permission of mnt directory files

I am not able to change the permission of files inside mnt directory.
Only owner (mysql) is having the rights to rwx but I am logged in using root still it is not able to change the permissions.
Is there any way of doing this?
First, it should be chmod -R 777 jol_main with -R, not -r.
Second, it seems that jol_main is on partition that is mounted as read-only. You can remount it as read-write with:
sudo mount -o remount,rw /dev/sdd3 /mnt/usb
( or without sudo if you are already a root )

Add permission to two users (my apache server and myself)

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 .

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.

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

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 *

Resources