Ubuntu: How to create two users who can read files of each other?


How to create 2 users a and b from shell, that will be able to read files of each other( say a can read the files of b, and b can read the files of a) .

sudo adduser newuser  sudo passwd newuser  


The classic way to do this is to make sure that both users belong to the same group. Then, you change the ownership of their files to that group. So, for example, to create bob and alice and allow them to read each other's files:

  1. Create the group that both users will belong to

    sudo addgroup users  
  2. Create the users, setting users as their primary group

    sudo adduser --ingroup users alice  sudo adduser --ingroup users bob  

That's it. Now, any files created by alice or bob will belong to the users group and since both users belong to that group, they will both be able to read them:

alice@foo $ echo "hello" > ~/file  alice@foo $ ls -l file  alice@oregano ~ $ ls -l file   -rw-r--r-- 1 alice users 6 May 11 16:12 file  


bob@foo $ cat ~alice/file  hello  


In a terminal (xterm is OK) execute cat /etc/group to obtain a list of available groups in your system; to add a custom group execute sudo addgroup group_name with a name of your choice.

Create the two users with the command you've written, then go to the directory with your files and execute sudo chgrp file or chown :group file to change their group to the one you've chosen before. After assign both users to the same group of the files with sudo usermod -a -G group username; this will not alter the existing assigned groups, don't worry.

Please feel free to comment under here if you have more questions and don't forget to press the left UP arrow if I'm of any help.
Welcome to the community. :)

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »