LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 04-10-2019, 05:11 AM   #1
dsl_
Member
 
Registered: Jul 2008
Location: Denmark
Distribution: Debian
Posts: 71

Rep: Reputation: 0
Trying to set up SFTP access to Ubuntu.


I've tried to follow this howto:

https://devanswers.co/configure-sftp...document-root/

which left me with an ssh service unable to start.

This one did better:

https://www.linode.com/docs/tools-re...an-and-ubuntu/

It works. My user can connect but he´s still not properly chrooted.

Have I missed something? Is there an error in the last howto?

Regards,
Søren
 
Old 04-10-2019, 05:26 AM   #2
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,328
Blog Entries: 3

Rep: Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726
Quote:
Originally Posted by dsl_ View Post
This one did better:

https://www.linode.com/docs/tools-re...an-and-ubuntu/

It works. My user can connect but he´s still not properly chrooted.
It looks ok, at a glance. The things to check would be :

1) that the chroot target is owned by root and not writable by other accounts.

2) that your account is a member of the group being chrooted

Aside from those things can you post what you've added to sshd_config?
 
Old 04-10-2019, 07:38 AM   #3
sunilpopaliya
Member
 
Registered: Apr 2012
Posts: 47

Rep: Reputation: 4
Hello,

You can follow below steps

1. create user with home directory which you want chrooted
2. owner for chrooted directory should be root with only root has write permission
3. make below changes in /etc/ssh/sshd_config file
#Subsystem sftp /usr/libexec/openssh/sftp-server
Subsystem sftp internal-sftp
Match User <your user name>
ChrootDirectory <directory which you want to chroot>
4. Refresh your ssh service with below command
kill -HUP <ssh service PID>

Thanks,
Sunil
 
Old 04-12-2019, 01:33 PM   #4
dsl_
Member
 
Registered: Jul 2008
Location: Denmark
Distribution: Debian
Posts: 71

Original Poster
Rep: Reputation: 0
I Haven't had a change to look at your suggestion yet sunilpopaliya, but I'm sure if Turbocapitalist wants to spar a little with me (I've deduced you're not a noob by now ), this probelem will be solved.

The problem is, as you say, that the parent of the directory where the SFTP user is dropped must belong to root and only to root. As it is, though, the user is dropped in his/her home dir and I dont really want to mess with /home.

I made the followoing changes to /etc/ssh/sshd_config:

Changed:

# override default of no subsystems
#Subsystem sftp /usr/lib/openssh/sftp-server
Subsystem sftp internal-sftp


Made this based on the group "filetransfer" per howto #2 above.

Now %h is obviously the user's /home directory as that as where they're put.

I've tried various forms of %h/ftp/home but without much luck, I'd rather jail a user a little into a directory a little further up the chain, or longer into their user home if you will.

Regards,
Søren
 
Old 04-12-2019, 01:42 PM   #5
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,328
Blog Entries: 3

Rep: Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726
Quote:
Originally Posted by dsl_ View Post
I've tried various forms of %h/ftp/home but without much luck, I'd rather jail a user a little into a directory a little further up the chain, or longer into their user home if you will.
The chroot and all the directories above it must be owned by root and not writable by anyone else, no matter how deep down it is is to be found. Another way around that problem is to chroot to /home/ since it meets those conditions and then move them immediately to their own home.

Code:
Match Group filetransfer
        ChrootDirectory /home/
        AllowTCPForwarding no
        X11Forwarding no
        ForceCommand internal-sftp -d %u
That assumes a normal system where the home directory matches the user name.

See also "man sshd_config", "man sftp-server", or Chrooted SFTP Accounts

If you don't want them to be able to sneak up a level and read the other home directories, then change the permissions to fix that.

Code:
sudo chmod 700 /home/*
sudo chmod 710 /home/*

# or

sudo chmod 750 /home/*
Edit: 710 and 750 assume that the group is still the same for the home directories and has not been changed to that of root. If even the group has been changed then use 701 or 705 instead. But it is best to leave the group unchanged for the home directories and merely adjust the permissions.

Last edited by Turbocapitalist; 04-16-2019 at 01:52 PM.
 
Old 04-16-2019, 01:27 PM   #6
dsl_
Member
 
Registered: Jul 2008
Location: Denmark
Distribution: Debian
Posts: 71

Original Poster
Rep: Reputation: 0
Ok This wasnt pretty. Instead of being put in his home directory hes now dropped in root /.

That was not a step in the right direction. To make matters worse he now has no permissions to enter his own home. I assume because that root now completely owns home. What are the default settings for /home? Im so smart I didnt look before applying the changes...

Man Im smart. (Thick sarcasm)

Last edited by dsl_; 04-16-2019 at 01:29 PM.
 
Old 04-16-2019, 01:39 PM   #7
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,328
Blog Entries: 3

Rep: Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726
Quote:
Originally Posted by dsl_ View Post
Ok This wasnt pretty. Instead of being put in his home directory hes now dropped in root /.
750 or 751 or 711 will work if the directory has the original group membership.

The defaults will be 755 for both /home/ and /home/* though for /home/* the owner of each directory would be the user and the group their primary group.

If you leave the group of the directory as the user's primary group but only change the owner to root, then you can use 751, 711, 750, or 710 for the permissions, assuming there is a subdirectory they can write to.

Code:
$ ls -lhd /home/ /home/dsl/ /home/dsl/dsl/
drwxr-x--x  4 root root 4.0K Mar 19 07:29 /home/
drwxr-x--- 53 root dsl  4.0K Apr 16 21:30 /home/dsl/
drwxrwx--- 54 dsl  dsl  4.0K Apr 16 21:30 /home/dsl/dsl/
To match

Code:
Match Group filetransfer
        ChrootDirectory /home/%u
        AllowTCPForwarding no
        X11Forwarding no
        ForceCommand internal-sftp -d %u
 
  


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
How to log internal-sftp chroot jailed users access log to /var/log/sftp.log file LittleMaster Linux - Server 0 09-04-2018 03:45 PM
SFTP using another account with passwordless sftp access jobart08 Linux - Newbie 3 03-23-2016 06:14 AM
cannot login into SFTP server using Net::SFTP cccc Programming 1 10-31-2007 06:23 AM
How do I use sftp to upload my web site? (no sftp tar command) johnMG Linux - Networking 6 06-21-2005 09:14 PM
Files truncated by sftp/sftp-server at 65kb gato Linux - Networking 1 12-18-2003 10:29 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 06:15 PM.

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