{"id":4552,"date":"2015-04-13T15:58:17","date_gmt":"2015-04-13T07:58:17","guid":{"rendered":"http:\/\/rmohan.com\/?p=4552"},"modified":"2015-04-13T15:58:36","modified_gmt":"2015-04-13T07:58:36","slug":"sftp-server","status":"publish","type":"post","link":"https:\/\/mohan.sg\/?p=4552","title":{"rendered":"SFTP server on chroot"},"content":{"rendered":"<p>SFTP server<br \/>\nSFTP ( 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 .<br \/>\nBasically we need openssh-server package to enable SFTP .<br \/>\nInstall openssh-server package, if its not already installed.<\/p>\n<p>yum -y install openssh-server<\/p>\n<p>Create a separate group for FTP access.<\/p>\n<p>groupadd ftpaccess<\/p>\n<p>Now open \/etc\/ssh\/sshd_config file and make changes as below.<br \/>\nFind and comment the below line ( Line no : 147 ).<\/p>\n<p>#Subsystem sftp \/usr\/libexec\/openssh\/sftp-server<br \/>\nand add these lines below.<br \/>\nSubsystem sftp internal-sftp<br \/>\nMatch group ftpaccess<br \/>\nChrootDirectory %h<br \/>\nX11Forwarding no<br \/>\nAllowTcpForwarding no<br \/>\nForceCommand internal-sftp<\/p>\n<p>Step 9 \u00bb Now restart sshd service.<br \/>\n[root@krizna ~]# systemctl restart sshd<br \/>\nNow your SFTP server is configured and ready .<\/p>\n<p>User creation<br \/>\nCreate user jack with \/sbin\/nologin shell and ftpaccess group<\/p>\n<p>useradd -m mohan -s \/sbin\/nologin -g ftpaccess<br \/>\npasswd mohan<\/p>\n<p>Now assign root ownership for the home directory for chroot access and modify permission.<br \/>\nchown root \/home\/mohan<br \/>\nchmod 750 \/home\/mohan<br \/>\nCreate a directory www inside home directory for writing and modify ownership .<\/p>\n<p>mkdir \/home\/mohan\/uploaded<br \/>\nchown mohan:ftpaccess \/home\/jack\/uploaded<\/p>\n<p>Now mohan can use both ftp and sftp services . He can upload files in www directory .<\/p>\n<p>Setup ftp server centos 7<br \/>\nIf 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.<\/p>\n<p>usermod test -g ftpaccess<br \/>\nchown root \/home\/test<br \/>\nchmod 750 \/home\/test<br \/>\nmkdir \/home\/test\/www<br \/>\nchown test:ftpaccess \/home\/test\/www<\/p>\n<p>Have a nice day.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>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 [&#8230;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[73],"tags":[],"_links":{"self":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/4552"}],"collection":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=4552"}],"version-history":[{"count":2,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/4552\/revisions"}],"predecessor-version":[{"id":4554,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/4552\/revisions\/4554"}],"wp:attachment":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4552"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4552"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4552"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}