linux sftp user jailed into home directory
- Check openssh version(Should newer than 4.8)
1 |
ssh -V |
- Edit ssh configuration file
1 2 |
cp /etc/ssh/sshd_config /etc/ssh/sshd_config.bak.20160606 vim /etc/ssh/sshd_config |
- Comment lines ‘Subsystem *’, add line:
1 2 |
#Subsystem sftp /usr/libexec/openssh/sftp-server Subsystem sftp internal-sftp |
- Add lines from bottom of the conf file
1 2 3 4 |
Match Group cardftp ChrootDirectory %h ForceCommand internal-sftp AllowTcpForwarding no |
- Restart sshd service:
1 |
service sshd restart |
- Create group
1 |
groupadd cardftp |
- Create user
1 |
useradd -g cardftp -d /ftp/card -s /bin/false cardftp |
- Correct directory ownership
1 2 3 4 |
chown root:cardftp /ftp/ chown root:cardftp /ftp/card/ chmod 755 /ftp chmod 755 /ftp/card |
- Give password to your sftp user