Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create a SFTP user to access only one directory. [closed]

I need to create a user which can only SFTP to specific directory and take a copy of some infomation. that is it. I keep looking online and they bring up information about chroot and modifying the the sshd_config.

So far I can just

  • add the user "useradd sftpexport"
  • create it without a home directory "-M"
  • set its login location "-d /u02/export/cdrs" (Where the information is stored)
  • not allow it to use ssh "-s /bin/false"

useradd sftpexport -M -d /u02/export/cdrs -s /bin/false

Can anyone suggest what am meant to edit so the user can only login and copy the file off?

like image 480
Alec George Doran-Twyford Avatar asked Apr 16 '14 04:04

Alec George Doran-Twyford


People also ask

How do I restrict SFTP to a directory in Windows?

Setting up Chroot JailOpen /etc/ssh/sshd_config and paste this at the end of the file. ChrootDirectory will force the user into a chroot jail that is their home directory and ForceCommand internal-sftp will make sure that anything located in .


2 Answers

I prefer to create a user group sftp and restrict users in that group to their home directory.

First, edit your /etc/ssh/sshd_config file and add this at the bottom.

Match Group sftp     ChrootDirectory %h     ForceCommand internal-sftp     AllowTcpForwarding no   

This tells OpenSSH that all users in the sftp group are to be chrooted to their home directory (which %h represents in the ChrootDirectory command)

Add a new sftp group, add your user to the group, restrict him from ssh access and define his home directory.

groupadd sftp usermod username -g sftp usermod username -s /bin/false usermod username -d /home/username 

Restart ssh:

sudo service ssh restart 

If you are still experiencing problems, check that the directory permissions are correct on the home directory. Adjust the 755 value appropriately for your setup.

sudo chmod 755 /home/username 

EDIT: Based on the details of your question, it looks like you are just missing the sshd_config portion. In your case, substitute sftp with sftpexport. Also be sure that the file permissions are accessible on the /u02/export/cdrs directory.

An even better setup (and there are even better setups than what I am about to propose) is to symlink the /u02/export/cdrs directory to the user home directory.

like image 163
csi Avatar answered Oct 04 '22 21:10

csi


You could need to add a restricted shell for this user can put some files there. You can use rssh tool for that.

usermod -s /usr/bin/rssh sftpexport 

Enable allowed protocols in config /etc/rssh.conf.

like image 25
user3132194 Avatar answered Oct 04 '22 19:10

user3132194