Difference between revisions of "Sftp chroot configuration"

From wikieduonline
Jump to navigation Jump to search
Line 40: Line 40:
 
=== 3) Review privileges from <code>[[ChrootDirectory]]</code>  directory ===
 
=== 3) Review privileges from <code>[[ChrootDirectory]]</code>  directory ===
  
== 4) [[Creating a new user]] ==
+
=== 4) [[Create a new user]] ===
 
  [[useradd --create-home]] USERNAME
 
  [[useradd --create-home]] USERNAME
 
  su - USERNAME
 
  su - USERNAME

Revision as of 11:49, 29 June 2020

Configuration



1) Modify Subsystem to internal-sftp

Modify /etc/ssh/sshd_config file
#Subsystem sftp /usr/lib/openssh/sftp-server
Subsystem sftp internal-sftp


2) Create a user section at the end of the file (ssh can die respawning if placed after Subsystem line)

Match User john
   ChrootDirectory %h
   ForceCommand internal-sftp
   AllowTCPForwarding no
   X11Forwarding no

Others:

  • %u (User)
  • %h (home directory)


Multiple users:

 Match User USER1,USER2


With double Match rule

Match User john LocalPort 2222 
   ChrootDirectory %h
   ForceCommand internal-sftp
   AllowTCPForwarding no
   X11Forwarding no

3) Review privileges from ChrootDirectory directory

4) Create a new user

useradd --create-home USERNAME
su - USERNAME
mkdir -p ~/.ssh
chmod og-rxw ~/.ssh
touch ~/.ssh/authorized_keys && chmod ogw-r ~/.ssh/authorized_keys
mkdir -p /path/to/directory/upload
chmod 777 /path/to/directory/upload
Add user on Match section on sshd_config file
sshd -t
systemctl restart sshd

Logs

scp error

 protocol error: mtime.sec not present

sshd -T

'Match LocalPort' in configuration but 'lport' not in connection test specification.


Related commands

See also

Advertising: