4

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
2
  • 2
    ever heard of "groups"? :)
    – Rinzwind
    May 11, 2014 at 13:56
  • No, I didn't. sudo addgroup group1 sudo adduser a group1 sudo addgroup group2 sudo adduser b group2
    – user280470
    May 11, 2014 at 14:04

2 Answers 2

4

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

and

bob@foo $ cat ~alice/file
hello
0
0

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. :)

2
  • Thanks much :) I misunderstood, I have to go to the directory, that contains my files, and change their group to the one I have just created? Thanks much in advance!!!
    – user280470
    May 11, 2014 at 14:29
  • Yes, and remember to assign both users to the same group. If you want to change the file owner of the files use 'chown user:group filename', it can be useful if you created the files as root or you can't access them. NOTE: you always need to execute 'chmod +x file' to make binary files executable. The groups are the most comfortable & secure way of managing the files; in any case avoid to modify the groups already configured by the system. For doubts on how to use an utility execute 'man softwarename', it will explain the syntax & the tricks to work better. May 11, 2014 at 15:36

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .