2

If I have 3 (or more) users on one computer, what's the best (easiest) way to let them share files between themselves?

The catch is that UserX should be able to send files to UserY without UserZ being able to get or see the files. Where X,Y,Z could be 1,2 or 3.
No user has the passwords of the others.


Basically If I'm User1 I want to be able to do send dir/file to User2 and User2 does receive from User1.

I have considered nc but it offers no guarantee that if User1 wants to send to User2 he won't actually be sending to User3.

Is shared directory my only option? Seems too messy if the files are big and user wants them in other place.

0

2 Answers 2

3

Why would you want to complicate with nc?

Set up three shared directories with shared groups (you've only three users so that's three distinct groups: u1-u2, u2-u3, u1-u3). Perform the work in these shared directories, so no copying is required.

1
  • I wanted more general solution as users will likely move the files to different place. But it also becomes messy the more users you have. Symlinking also seems kind of meh. I've spend few hours trying to find good and simple solution but it seems shared dirs is the best so far. (still waiting to see if there is some other way) Commented Nov 4, 2019 at 0:30
2

Users have the right to set ACLs for their own files.

To allow john to "send" a file only to as specific user (joe), simply make john execute e.g.:

setfacl -m u:joe:rw file

For allowing user joe to access the file. Of course the standard permissions would have to exclude access by joe (i.e. joe not being group member of group john and no access permission to others). Set the setfacl command to your liking and if you want to make a "send" command with a simple script, here would be a suggestion:

#!/bin/bash

print_help(){
  echo "Usage: sendfile -u <user> file1 file2 ..."
  exit 1
}

while getopts "u:h" option
do
  case $option in
    u) user=$OPTARG
       if [[ "$(grep ^${user}: /etc/passwd)" == "" ]]
       then
         echo "$user not a valid user."
         exit
       fi ;; 
    h) print_help ;;
    *) print_help ;;
  esac
done 


if ((OPTIND == 1))
then
    echo "No user specified"
    exit 1
fi

shift $((OPTIND - 1))

setfacl u:${user}:rw "$@"

Of course ACLs need to be enabled in the first place.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.