6

With proftpd you can change the default directory editing /etc/proftpd.conf
DefaultRoot ~
change to
DefaultRoot ~/music

How i can achieve the same result with SFTP?

Im using ubuntu lucid btw.

Ty so much for your help.

1
  • Which software are you using?
    – Khaled
    Nov 1 '10 at 17:28
8

Have a look at this article which shows how to use sshd's ChrootDirectory to force all members of a particular group into a common directory root. You may be able to modify it to meet your requirements.

2
  • Ty for your answer and the article d(^.^)b
    – Jonathan B
    Nov 1 '10 at 20:06
  • you can also use Match User
    – Moog
    May 2 '12 at 21:38
23

Unfortunately I don't have enough reputation to comment because all I wanted to do is stress how important the comment by Richard Fairhurst is and how it should be added to the "official answer". I have seen people here and elsewhere having trouble setting the user home directory or having the user home directory as a "default directory". That's just because in a chroot environment the root directory is not the / any more. Meaning any other path should be relative to the new root path. Ex:

if you chroot to /home and want the default directory to be /home/default you should set the user home directory to /default. Not /home because /home will be the new /.

If you really need to keep the user home directory in /home/user but wish to have a default directory for sftp sessions, you can use the -d parameter for internal-sftp. Like in this example:

Subsystem sftp internal-sftp
Match Group sftpusers
    ChrootDirectory /mnt/sftp
    ForceCommand internal-sftp -d /default

/default being a directory inside /mnt/sftp. Notice that path here is again relative to the new root.

1
  • how to do this with openssh < 6.2 ?
    – Dejan
    Apr 20 '17 at 14:30
4

Perhaps there is a way to achieve what you want but as far as I know, sftp is operated over ssh so not so sure how to do that with ssh for every user.

However, one way to get around what you want to do is that you can update the user data to log in to certain directory as follows. This will w

$ sudo usermod -d [certain path that you want to direct] username
2
  • ok thx ill try it d(^.^)z
    – Jonathan B
    Nov 1 '10 at 20:01
  • unfortunately, for me this does not translate to the default directory of a sftp user@server login. This is probably referring to the ssh login?
    – 0-_-0
    Jun 30 at 18:26
2

lain's answer was helpful, but in the interest of being more explicit, and not depending on a link(and so I can find it next time):

Search the web for ChrootDirectory, to get the basic docs and setup, I'll not replicate them here, only point out how to solve the asked question.

For a dedicated file server use: Match Group *,!sudo so anybody who's not an admin get chrooted sftp only access - by default.

Set ChrootDirectory /home/%u -- chroot is based on username, not their home-directory

Make sure the users directory in /home is owned by root:root

Set the home-directory path in /etc/passwd to the directory you want to be logged into by default - but make it relative to the chroot directory:

If you want the user acnt to end up in /home/acnt/files/, then set the passwd home for acnt to /files

Make sure that /home/acnt/files is owned by acnt:acnt, so that the user can write to the directory, even though /home/acnt/ must be owned by root for the chroot jail to function.

1
  • 2
    Slight correction: If you want the user account to end up in /home/acnt/files, then set the passwd home to files (no leading slash). Jun 17 '14 at 11:25
0

I just went through the same sort of thing with an Ubuntu Lucid 10.04 install. The answer seems to be to chroot certain logins to a specific folder. The only disadvantage being that the folder that they are chrooted to must be owned by root:root and can't be writable by the user logging in in order for ssh to allow the sftp login to work. SO, they only have access to other folders within the folder that they are chrooted to.

http://ubuntuforums.org/showthread.php?t=1057657

Also, setting the default folder for the user using "usermod -d doesn't change the default for that user going to the root / folder upon sftp login.

1
  • Ty ill give it a try
    – Jonathan B
    Nov 11 '10 at 5:53
0

If you're using ProFTPD, then take a look at the ProFTPD SFTP module.

1
  • I don't see it, can you point me to the source?
    – Dejan
    Apr 20 '17 at 14:32

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.