Can create / edit groups file but can't change permission - linux

my scenario is:
2 users : firstUser and secondUser in developers group.
This user connect to server with sftp;
if firstUser create a file, this file was 775 , ownered by firstUser, group developers;
with secondUser i can edit and write this file but if i try:
chmod 777 testfile.txt
I can't do that!

Could you provide the results of 'ls -l testfile.txt'. There are two ways you can try to resolve this. I am unsure if they would be the best approach but here they are. Add a sudo prior to the chmod, e.g., 'sudo chmod 777 testfile.txt' and supply the root password. Or you could change the owner, e.g., 'chown secondUser:developersgroup testfile.txt' then chmod.

only root or the owner can do that.

Related

How to give permission to root user generated file by other user in linux?

I am trying to giving permission to root user generated file but not able to do this. Can anyone help me how to do this?
I tried:
echo -e 'password'> sudo chmod 777 file.txt
Example:
file.txt rw-r--r-- root
Expected result:
file.txt rwxrwxrwx spate233
First of all, I can't see what you're doing by "echo -e 'password'".
The '>' character means "output redirection", that is, bash will redirect the input of the "echo -e password" command to a file named "sudo" in the directory that you're working. The part "777 file.txt" will be appended to that file(i didn't know this, I just tested it in my PC and that's what happened).
Apart from that: if you want to access a root generated file you have to take into account that root generated files have "root" as owner and "root" as owner group.
If the user that you're trying to give permissions is a sudoer, then you can just operate using "sudo", just like you did in the example.
If it is not, and you want your user to have permissions, it would be enough to set permissions for "other" domain. You can try this:
sudo chmod o+rwx file.txt
This adds all permissions (i.e. rwx) to the other users domain.
However, if you want to give 777 permissions to the file, you just use
sudo chmod 777 file.txt
or also, if you want to use a syntax like the previous one
sudo chmod a+rwx file.txt
If it your desire, then you can also change the owner of the file. Doing this can lead to some security problems, so it is avoided if the file you are dealing with is a system file. I think this is not the case, so you can just do:
sudo chown user:group file
Where user and group are substituted with the new owner and the new group of that file.

how do i change mac folder permission?

If I Enter ls -al in the Mac terminal, The results are as follows. Like the first line, I want to change _mysql to chowon but I don't know how to do that.
In fact, several attempts were made through chmod commands but were unsuccessful.
In order to change the permission, you should first have the permission to do that. Mostly those are administrators or root users. Please show us the result of who am i or try to start the chmod command with a sudo: sudo chmod .... You'll be asked for a password in order to do this.
Can you try changing the owner and group from _mysql and admin to chowon and staff like this :
chown chowon .. # To change the owner
chown chowon:staff .. # To change the owner and group
You need to add sudo in front of these commands if you get Operation not permitted.

How allow folder permission for another user in Linux

Consider two user accounts user1 and user2 on one Linux machine. I want user2 to be able to have read and write access to a folder in user1 home directory.
So far created a group for both users and added both users
groupadd twousers
usermod -a -G twousers user1
usermod -a -G twousers user2
then changed the group and the path and changed the permission
chgrp twousers /home/user1/folder
chmod g+rwx /home/user1/folder
Unfortunately user2 is still unable to access the folder /home/user1/folder. It seems to be quite simple but somehow I am lost. What am I missing?
chown user1.twousers /home/user1/folder
chmod 775 /home/user1/folder
Just try this until you get the permission and make sure you don't mess up the path or name of the file or folder:
chmod u+rwX,g+rwX,o+rwX

Give access to my application to read/write a file on var/www

In my application, I need to write a file.json in /myserver/home/www/var/myApplicationFolder/file.json but it does not work. (there is no problem in the code as it has already been tested)
I think it because of the root permission .
What should I do?
If you'd like any account on the server to be able to write to this folder then run:
sudo chmod 777 /myserver/home/www/var/myApplicationFolder/
or if you'd just like it to be able to write to that specific file:
sudo chmod 777 /myserver/home/www/var/myApplicationFolder/file.json
The chmod command takes 3 numbers which correspond to the permissions that the owner, people in the group, and everyone else gets respectively. The issue with the older answer was that they where giving the owner all the permissions (the first 7), but no giving any permissions to anyone else (the second and third 5).
In the terminal run the command:
sudo chmod 755 /myserver/home/www/var/myApplicationFolder/
it should work.

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 .

Resources