LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-22-2021, 09:53 PM   #1
Varister
LQ Newbie
 
Registered: Oct 2021
Posts: 5

Rep: Reputation: Disabled
How do I create public and private directories for new users?


I am trying to write a script to create a public and private directory for each newly created user in their home directories. I would like to change the ownership of the private directory to the user and their group, but only to be accessible by the user and no one else. I would like to change the ownership of the public directory to the user and their group and allow anyone to access the public directory. What commands or techniques would I use to create this?
 
Old 10-22-2021, 10:03 PM   #2
frankbell
LQ Guru
 
Registered: Jan 2006
Location: Virginia, USA
Distribution: Slackware, Ubuntu MATE, Mageia, and whatever VMs I happen to be playing with
Posts: 17,808
Blog Entries: 28

Rep: Reputation: 5543Reputation: 5543Reputation: 5543Reputation: 5543Reputation: 5543Reputation: 5543Reputation: 5543Reputation: 5543Reputation: 5543Reputation: 5543Reputation: 5543
A user's home by default is private. Off the top of my head, you may want to take a look a creating a directory within user's home and configuring it to be shared via Samba.

Others much more knowledgeable than I may have better--and more detailed--takes on this.

Last edited by frankbell; 10-22-2021 at 10:03 PM. Reason: grammar
 
Old 10-22-2021, 10:51 PM   #3
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 5,971
Blog Entries: 3

Rep: Reputation: 3102Reputation: 3102Reputation: 3102Reputation: 3102Reputation: 3102Reputation: 3102Reputation: 3102Reputation: 3102Reputation: 3102Reputation: 3102Reputation: 3102
The method would be shell scripting, there are a number of guides out there but you might start with ordering a copy of The Linux Command Line and working through to part four. Your script will rely on permissions and groups so, chmod and chgrp will be important.

Code:
ls -lhd /home/varister/ /home/varister/private/ /home/varister/public/
drwx-----x 78 varister varister  12K Oct 23 05:46 /home/varister/
drwxrwx--- 55 varister varister  12K Oct 18 04:32 /home/varister/private/
drwxr-xr-x  2 varister varister 4,0K Jun 28  2019 /home/varister/public/
Note the o=x in the home directory, that will allow passing through but not browsing.

And if you are making more new users, you might also look into learning how to populate /etc/skel/

Which distro is this for?
 
Old 10-22-2021, 10:51 PM   #4
b1bb2
LQ Newbie
 
Registered: Oct 2021
Posts: 24

Rep: Reputation: Disabled
I guess your script language is bash? One command is mkdir. Another is chmod. I think there is one to create a new user. These commands will do some of the things you are asking for. So after applying these commands, what parts do you not know how to do? It might help narrow down the problem if you post the parts of your script that works.
 
Old 10-22-2021, 10:55 PM   #5
frankbell
LQ Guru
 
Registered: Jan 2006
Location: Virginia, USA
Distribution: Slackware, Ubuntu MATE, Mageia, and whatever VMs I happen to be playing with
Posts: 17,808
Blog Entries: 28

Rep: Reputation: 5543Reputation: 5543Reputation: 5543Reputation: 5543Reputation: 5543Reputation: 5543Reputation: 5543Reputation: 5543Reputation: 5543Reputation: 5543Reputation: 5543
It's a bit long in the tooth, but Mendel Cooper's Advanced BASH Scripting Guide might be a good resource. BASH hasn't changed all that much since it was last revised.
 
Old 10-24-2021, 01:31 PM   #6
GazL
LQ Veteran
 
Registered: May 2008
Posts: 6,202
Blog Entries: 1

Rep: Reputation: 4268Reputation: 4268Reputation: 4268Reputation: 4268Reputation: 4268Reputation: 4268Reputation: 4268Reputation: 4268Reputation: 4268Reputation: 4268Reputation: 4268
I'm not a fan of the o=x approach: if the user is not very careful about permissions/umask they can have their files in $HOME exposed.

Personally, I'd go with a separate /pub/$USER hierarchy and then ln -s /pub/$USER /home/$USER/pub. This keeps everything in $HOME private.

Last edited by GazL; 10-24-2021 at 01:34 PM.
 
Old 10-26-2021, 02:27 PM   #7
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 9,434
Blog Entries: 4

Rep: Reputation: 3376Reputation: 3376Reputation: 3376Reputation: 3376Reputation: 3376Reputation: 3376Reputation: 3376Reputation: 3376Reputation: 3376Reputation: 3376Reputation: 3376
Typically, a user's /home directory should be private: -rwxrwx---.

One common practice is to set up some set of directories, say within the customary /usr/local/share directory, which are owned by individual users and their associated group.

For instance, the permissions for one subdirectory can then be set to -rwxrwx-wx, which makes the directory write-only to the general public. Like MacOS's "Drop Box" folders. Other users can put things into it, and can access them if they know their name, but they can't list the files that are inside. (Also consider: -rwxrwx-w-.)

You can also set up another subdirectory in the same area which users can use to place files and folders that other users can see but cannot touch: -rwxrwxr-x.

As a "rootly god," setting up such a directory is an easy exercise in mkdir, chown, chmod.

ACLs = Access Control Lists are another option which I won't go into here.

Last edited by sundialsvcs; 10-26-2021 at 02:32 PM.
 
Old 10-26-2021, 05:15 PM   #8
GazL
LQ Veteran
 
Registered: May 2008
Posts: 6,202
Blog Entries: 1

Rep: Reputation: 4268Reputation: 4268Reputation: 4268Reputation: 4268Reputation: 4268Reputation: 4268Reputation: 4268Reputation: 4268Reputation: 4268Reputation: 4268Reputation: 4268
Quote:
Originally Posted by sundialsvcs View Post
Typically, a user's /home directory should be private: -rwxrwx---.
I'm not sure how true that is. I've seen a default of 751 used by several distros. You tend to see it where the distro has configured the web server to serve user-dirs from ~/public_html, or similar.

I normally go full-paranoia-mode with mine, and make it 700.
 
  


Reply

Tags
bash, scripting, unix


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I convert a putty private key to be used as a private key on a RedHat or Ubuntu Server greavette Linux - General 2 06-26-2019 09:40 PM
Is Private Web Browsing Really Private? LinuxCrushesWindows Linux - Software 16 03-03-2014 01:38 PM
LXer: A Call to Support a New Public-Private Partnership In U.S. Standards Development LXer Syndicated Linux News 0 12-13-2010 01:40 PM
Accessing a private LAN from another private LAN sholah Linux - Networking 3 07-10-2007 09:17 PM
LXer: Keep your private documents private LXer Syndicated Linux News 0 06-07-2006 04:21 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:55 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration