I have a processing machine that is running on Linux and is used by many people. This machine has only one user where people using this machine can login and use the machine. What I wanted to do is to create a folder for each person where they can place their data and it will be secured using their email and password for example, so that others will have access to everything except other people private folders. So for example in ~/Documents there will be a folder for each person where only this person can access the content of this folder. Any advice?

  • 1
    you need a separate account for each user. – cas Jan 16 '18 at 15:20
  • @cas but they use everything in the machine all together, how I can do this? Like I want them to see and use everything in the machine (applications,....) except folders of other people. – Tak Jan 16 '18 at 15:22
  • if you only have one user account, there is no way for the system to know who is using it at any given moment. The best you could do without individual user accounts is an "honour system" and hope that other people don't sneak a look at someone else's private files. – cas Jan 16 '18 at 15:31
  • @cas What is an "honour system"? – Tak Jan 16 '18 at 16:05
  • an honour system is where you trust to the honour of people not to do bad things. with predictable results. – cas Jan 16 '18 at 16:06

You need a separate account for each user. There's no way around this if you want users to be able to have private files.

If you also need a shared documents folder (as well as each users private folder), then create a unix group, add all users to that group, use chgrp to set the shared directory's group-owner to that group, and chmod g=rwsX on the directory to enable all group members to read, write, cd into, list files, etc. This s (sticky bit) in the g=rwsX chmod mode makes sure that all files and subdirectories created in the shared directory are also owned by that group.

For example:

addgroup --group shared    # create group called 'shared'

addgroup username shared   # add username to group 'shared'. repeat for every user

mkdir /home/shared
chgrp shared /home/shared
chmod g=rwsX /home/shared

You can either create a symlink in each users' home directory pointing to /home/shared (and create one in /etc/skel too so newly created users get it by default), or just tell everyone to look for shared files in /home/shared.

  • what if I had 100 users? I'll make 100 user accounts on the machine? – Tak Jan 18 '18 at 10:34
  • yes. alternatively, make accounts for those who want private space, and a shared account for everyone else. BTW, it's not terribly difficult to script the process of adding accounts, just use the right command line options to adduser so that it doesn't have to prompt for everything (and use --disabled-password - you can set the passwords later in the script with chpasswd). For passwords, generate a file containing a line 'username:random_password' for each user and pipe that into chpasswd. Then give each user their personal password and tell them to change it ASAP. – cas Jan 18 '18 at 11:07
  • Thank you, I've upvoted your answer. Is it possible to update your answer with a script that process adding accounts? As I'm not good with commands and scripts. Thanks again in advance – Tak Jan 18 '18 at 12:29
  • here's an example: unix.stackexchange.com/a/79912/7696. You'll need a list of username and real names (for the GECOS field). You also need a list of usernames and passwords. You can generate random passwords with tools like pwgen or makepasswd. Your script will need to loop around the adduser command, once for each user. You can just pipe the entire file with username:password into chpasswd in one go. If you have trouble implementing that, post a new question showing what you've done so far and what you're having trouble with. – cas Jan 18 '18 at 14:39
  • btw, you'll also need to distribute the passwords to the users. one simple way is to print the username:password list with a few lines between each user, and cut it into small strips, one for each user with their login details. remind them to change their password as soon as the log in. or you can force that with chage -d 0 username (see unix.stackexchange.com/questions/173708/…) – cas Jan 18 '18 at 14:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.