LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   How to make a public folder within a private folder? (https://www.linuxquestions.org/questions/linux-general-1/how-to-make-a-public-folder-within-a-private-folder-833566/)

Virchanza 09-21-2010 09:58 AM

How to make a public folder within a private folder?
 
My Linux username is "virchanza" and my group is "virchanza". Here's how my home folder looks:

Code:

virchanza$ ls -alhd /home/virchanza
drwx------ 59 virchanza virchanza 20K 2010-09-21 20:55 virchanza

As you can see, I have full access to my home folder, but my "group" and "others" have no access whatsoever.

Inside my home folder, I want to create a publicly accessible folder called "public_stuff":

Code:

virchanza$ cd
virchanza$ mkdir public_stuff
virchanza$ chmod 777 public_stuff
virchanza$ ls -alhd public_stuff
drwxrwxrwx 2 virchanza virchanza 4.0K 2010-09-21 21:32 public_stuff

OK, you can see that this "public_stuff" folder has full access permissions for everyone. Now I'm gonna create a file inside this folder:

Code:

virchanza$ cd public_stuff
virchanza$ echo "One two three four five" > file.txt
virchanza$ chmod 777 file.txt
virchanza$ ls -alh
total 40K
drwxrwxrwx  2 virchanza virchanza 4.0K 2010-09-21 21:35 .
drwx------ 60 virchanza virchanza  20K 2010-09-21 21:32 ..
-rwxrwxrwx  1 virchanza virchanza  24 2010-09-21 21:35 file.txt

Now I'm going to navigate back to the "/home" folder and switch to a different user

Code:

virchanza$ cd /home
virchanza$ su guest_user
Password:
guest_user$ cat /home/virchanza/public_stuff/file.txt
cat: /home/virchanza/public_stuff/file.txt: Permission denied
guest_user$

I thought this would work... but it doesn't.

How do I make a publicly-accessible folder within my private home folder?

alunduil 09-21-2010 10:05 AM

In order for someone to see a file a few permissions need to be in place:

First, they have to have access to the file itself which you've done.
Second, All the directories leading to that file must be executable by the person who wants to browse to this file.

I would recommend setting up a public location in a common directory rather than in your home directory for this purpose.

Regards,

Alunduil

Virchanza 09-22-2010 12:18 AM

Hey Alunduil thanks a lot for your reply.

I got everything working the way I wanted it.

The "public folder" which I want to keep inside my private home folder actually contains the files for my website (I have a web server demon running on my machine) . I want to keep my website files within my home folder.

I added "o+x" to my home folder permissions so now everything is working fine (people can navigate into my home folder but they are unable to view its contents because I didn't specify "o+r" for my home folder).

Thanks a lot for your help!

Virchanza

alunduil 09-22-2010 08:13 AM

No problem. Just for further edification:

* If you would ever need to delete that user (which I doubt you would) you don't want to delete the user's information because now the website would be deleted as well.
* Setting up websites that are accessible in this manner is typically best solved by setting up the website in a www directory (usually in /var) and then symlinking that directory into the home directory.

I'm glad everything is working just wanted to provide a couple of alternatives.

Regards,

Alunduil


All times are GMT -5. The time now is 12:31 PM.