November 2024
M T W T F S S
 123
45678910
11121314151617
18192021222324
252627282930  

Categories

November 2024
M T W T F S S
 123
45678910
11121314151617
18192021222324
252627282930  

SFTP server on chroot

SFTP server
SFTP ( Secure File Transfer Protocol ) is used to encrypt connections between clients and the FTP server. It is highly recommended to use SFTP because data is transferred over encrypted connection using SSH-tunnel on port 22 .
Basically we need openssh-server package to enable SFTP .
Install openssh-server package, if its not already installed.

yum -y install openssh-server

Create a separate group for FTP access.

groupadd ftpaccess

Now open /etc/ssh/sshd_config file and make changes as below.
Find and comment the below line ( Line no : 147 ).

#Subsystem sftp /usr/libexec/openssh/sftp-server
and add these lines below.
Subsystem sftp internal-sftp
Match group ftpaccess
ChrootDirectory %h
X11Forwarding no
AllowTcpForwarding no
ForceCommand internal-sftp

Step 9 » Now restart sshd service.
[root@krizna ~]# systemctl restart sshd
Now your SFTP server is configured and ready .

User creation
Create user jack with /sbin/nologin shell and ftpaccess group

useradd -m mohan -s /sbin/nologin -g ftpaccess
passwd mohan

Now assign root ownership for the home directory for chroot access and modify permission.
chown root /home/mohan
chmod 750 /home/mohan
Create a directory www inside home directory for writing and modify ownership .

mkdir /home/mohan/uploaded
chown mohan:ftpaccess /home/jack/uploaded

Now mohan can use both ftp and sftp services . He can upload files in www directory .

Setup ftp server centos 7
If you are going to use FTP and SFTP together in the same server, you should follow above steps while creating users . For existing users add them to ftpaccess and make below changes.

usermod test -g ftpaccess
chown root /home/test
chmod 750 /home/test
mkdir /home/test/www
chown test:ftpaccess /home/test/www

Have a nice day.

Leave a Reply

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>