LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Security
User Name
Password
Linux - Security This forum is for all security related questions.
Questions, tips, system compromises, firewalls, etc. are all included here.

Notices


Reply
  Search this Thread
Old 08-04-2017, 09:33 AM   #1
jordonblackstock
LQ Newbie
 
Registered: Aug 2017
Posts: 4

Rep: Reputation: Disabled
guest access to a folder - ftp


Hi,

I have built a ubuntu server, which hosts all my media, where i have mounted my hard drives on to 3 folders (e.g. hard drive1 = moives, hard drive2 = movies2, hard drive 3 = extra files)

i want to be able to create a new user, user2, to only have access to the 'movies2' folder over ftp, but also let user1 (admin account) to have access to the same folder.
 
Old 08-04-2017, 10:30 AM   #2
MensaWater
LQ Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, CoreOS, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 7,831
Blog Entries: 15

Rep: Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669
First: Do NOT use ftp - it is very insecure. Use sftp instead.

What you want to do is create a jailed sftp user. You can find tutorials all over the internet for that such as this one:
https://www.tecmint.com/restrict-sft...-using-chroot/

Even if the person you wish to access the directory has Windows rather than Linux they can access sftp logins by installing WinSCP on their Windows machine. (WinSCP can also access standard ftp as well.)
 
Old 08-04-2017, 11:04 AM   #3
jordonblackstock
LQ Newbie
 
Registered: Aug 2017
Posts: 4

Original Poster
Rep: Reputation: Disabled
i forgot to mention that the folder, which i require user2 to have access to is located in user1 home dir
 
Old 08-04-2017, 11:45 AM   #4
MensaWater
LQ Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, CoreOS, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 7,831
Blog Entries: 15

Rep: Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669
You make the jailed user2 home in the movies2 directory. If you jail him properly he'll see movies2 as if it were "/" while your user1 will still see it as /home/user1/movies2.

What we do here instead is create a separate subdirectory as the parent for jailed users (we have multiple) such as:
/home/restricted

We'd then jail the user under that in say /home/restricted/user2.

We then put links to that in any non-jailed directories we might want to share with e.g.

ln -s /home/restricted/user2 /home/user1/movies2

This allows user1 to write into it as if it were under his home directory. When user2 logs in he is really in /home/restricted/user2 but thinks he is in "/" so can't see anything really above him such as /home/restricted itself, /home or the real "/" (root) of the system. This is the point in doing the jailing.
 
Old 08-04-2017, 02:11 PM   #5
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,309
Blog Entries: 3

Rep: Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721
Yes, please don't use FTP any more.

About chrooted SFTP, it is easy enough to set up provided the chroot is owned by root and not writable by anyone else. So that means doing a little differently for the chrooted users' home directories.

If you have the two users' directories set up like this:

Code:
$ awk -F: '$1 ~ /user./ { print $1,$6; }' /etc/passwd 
user1 /home/user1/user1
user2 /home/user2/user2

$ ls -lhd /home /home/user? /home/user?/user?
drwxr-xr-x 5 root  root  4.0K Aug  4 20:58 /home
drwxr-xr-x 3 root  root  4.0K Aug  4 20:58 /home/user1
drwxr-xr-x 5 user1 user1 4.0K Aug  4 20:58 /home/user1/user1
drwxr-xr-x 3 root  root  4.0K Aug  4 20:58 /home/user2
drwxr-xr-x 3 user2 user2 4.0K Aug  4 21:58 /home/user2/user2
And if you have put them both in a group, such as sftponly, and chrooted with openssh-server like this:

Code:
Match Group sftponly
        ChrootDirectory /home/%u
        AllowTCPForwarding no
        X11Forwarding no
        ForceCommand internal-sftp -d %u
Then they can only connect with SFTP and even then they only see their own directories.

Symbolic links won't work if they point to outside the chroot however. You can use a bind mount instead. If your movies are in /home/movies and /home/movies2 then you can give the access to chrooted user2 like this:

Code:
mount --bind /home/movies/   /home/user2/user2/movies 
mount --bind /home/movies2/  /home/user2/user2/movies2
Thus they will show up in the user's home directory as subdirectories "movies" and "movies2"

Last edited by Turbocapitalist; 08-04-2017 at 02:12 PM.
 
Old 08-04-2017, 02:28 PM   #6
jordonblackstock
LQ Newbie
 
Registered: Aug 2017
Posts: 4

Original Poster
Rep: Reputation: Disabled
my folders are as follows:

/home/'user1'/movies/
/home/'user1'/movies2/'user2'
/home/'user1'extra/
 
Old 08-04-2017, 02:30 PM   #7
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,309
Blog Entries: 3

Rep: Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721
Quote:
Originally Posted by jordonblackstock View Post
my folders are as follows:
Ok. Then adjust your binds accordingly. First step, though, would be to chroot SFTP for user2.
 
1 members found this post helpful.
Old 08-05-2017, 01:19 AM   #8
jordonblackstock
LQ Newbie
 
Registered: Aug 2017
Posts: 4

Original Poster
Rep: Reputation: Disabled
Thanks! that worked, they can no longer see my other files but i can see theres

Appreciate the help
 
Old 08-05-2017, 02:06 AM   #9
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,309
Blog Entries: 3

Rep: Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721
No problem.

One thing you might have seen in the mount manual page regarding the binds is that they won't persist across reboots unless you add them to /etc/fstab So if you have them the way you want, then add them to fstab so they'll still be there after a reboot.
 
  


Reply



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
LXer: How To Access Virtualbox Shared Folder From Ubuntu 12.04 Guest Machine LXer Syndicated Linux News 0 06-09-2012 07:00 AM
How to allow guest access a folder on linux ? ngohieutp Linux - Server 1 02-23-2010 12:02 AM
how is it possible to stop access to few folder with FTP? dussel Linux - Security 1 07-06-2006 04:53 AM
FTP access to home folder deWin Linux - Networking 5 04-26-2004 01:45 AM
ftp guest access c0c0deuz Linux - Software 2 01-31-2002 04:56 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Security

All times are GMT -5. The time now is 08:51 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