Change ownership and permissions on folder

How can I change the ownership and permissions of a folder an content?

Must be something like that: chown -R <user/group> /home/armin/…

Yup - you got it

ownership

chown $USER:$USER  --recursive /path

permissions (user group other +/-r,+/-w,+/-x)

chmod u+rw,go-w --recursive /path

Is it like the following:

chown -R armin:user /home/armin/…

If you want the home folder to be accessible to all members of the group user then it is correct

If you just want to ensure you own all files in your home then use the group created your username or omit the group

chown armin --recursive /path

or

chown armin:armin --recursive /path

There is more in the man pages

man chown
man chmod

It is safe to create a temporary folder with some files and folders in your home and then use that folder to experiment with the various options to learn how different permissions affect the accesibility and actions.

E.g. to be able to navigate into a folder permissions need to be x on the folder. This fact is often use to hide subfolders as you can navigate directly to a folder in a known tree without having permissions to navigate the immediate folder

E.g. ./temp has -x but you have +x on temp1 - which means that cd ./temp/temp1 will work despite you have no access to ./temp

$ tree ./temp
./temp
├── m001c8ce6.txt
├── m1c2df351.txt
├── m1c8631fd.txt
└── temp1

1 directory, 3 files

I have copied 2.3GB of data from BD-RE to the home folder.
Now these files are write protected.

Now I want to have write access for the user armin the folder xy.

What I have tried:

chown -R armin:user /home/armin/xy
leads to read access for the user armin and read/write access to user.

chown -R armin /home/armin/xy
leads to read access for the user armin.

But what I want:
read/write access for user armin.

man chown
helps to understand

you can read this:
chown -R armin:user /home/armin/xy

as:
recursively change ownership of this directory
making the contents belong to
user=armin and group=user
(before the colon is the user, after the colon is the group)

And there is your problem:
there is no such group - there is no group named “user”

There is one named “users”
and user armin can be a member of it
But I think, by default, he is not

so what you want is this:

chown -R armin:armin /home/armin/xy

or this:

chown -R armin:users /home/armin/xy

You can check the permissions that are normally present in your $HOME directory with:
ls -hl

and then make your xy directory the same …

Die Gruppe heißt “users” - nicht “user
Und Du bist per default noch nicht Mitglied.

(um das Verwirrungspotential zu maximieren, kannst Du natürlich eine Gruppe mit dem Namen “user” erzeugen … dann hast Du “user” und “users” und “armin” ist immer noch in keiner von beiden :wink: )

translation (because automated translators will totally screw this up, as I just noticed):
to maximize the potential for confusion
you can create a group named “user” … then you have “user” and “users”
and “armin” is still not a member of either one :wink:

gpasswd ist ein Werkzeug mit dem man das tun kann.
gpasswd -a user group
heißt: füge den Benutzer “user” der Gruppe “group” hinzu

Now these files are write protected.

When you change ownership, you do not change file attributes, such as read,write, execute permissions.
That is done with the command chmod

chmod -R ugo+w /home/armin/xy
ugo+w means: user,group,others add write permissions

man chmod

The command:
groups
gives you a list of groups your user account currently is a member of

Now I have executed
chown -R armin:users /home/armin/xy

Now I have read/write access to the folder xy.

But there is a lock at the folders below the folder xy.

ls -hl /home/armin/xy
or
ls -hl /home/armin

you have no write permissions - or no execute permissions, or both - I never use the graphical filemanager and can’t say what that lock symbol means

chmod is the command to change these read write and execute permissions

and as I said:

You are, by default, not a member of the group “users”

Or are you?
groups
will tell you

group says:
sys network power wheel armin

That means that you are NOT a member of the group “users” - it is not in that list.

chown -R armin:armin /home/armin/xy
chmod -R ugo+rw /home/armin/xy

is probably what will give you ownership as well as read and write permissions

The best, AFAIK, for your home directory and contents is:

sudo chown $USER:$USER ~

NOT this:

 chown -R armin:users /home/armin/xy

It is nonsensical. Except if you’ve actually got the group users.

I’d do that recursively - but it will not fix missing read or write permissions …

True, forgot about that, my bad.:

sudo chown --recursive $USER:$USER ~

Quite possibly not. For that he’d have to change/correct the ownership first and then make sure to set the right permissions with chown.

More info:

man chown

Thanks for the support!

3 Likes

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.