{"id":194,"date":"2012-06-11T07:49:54","date_gmt":"2012-06-11T07:49:54","guid":{"rendered":"http:\/\/rmohan.com\/?p=194"},"modified":"2012-06-11T07:51:12","modified_gmt":"2012-06-11T07:51:12","slug":"vsftp","status":"publish","type":"post","link":"https:\/\/mohan.sg\/?p=194","title":{"rendered":"VSFTP"},"content":{"rendered":"<p>CentOS 6<\/p>\n<p><strong>vsftpd 2.2.2<\/strong><\/p>\n<p>su &#8211; root<\/p>\n<p>yum install vsftpd<\/p>\n<p>cd \/etc\/vsftpd\/<\/p>\n<p>vi config<\/p>\n<p>anonymous_enable=NO  This is set to YES by default.<\/p>\n<p>local_enable=YES     This is set to NO by default and change when you want the local users to have ftp access.<\/p>\n<p>xferlog_enable=Yes   This is set to NO by default. Your logs will be written to \/var\/log\/xferlog.<\/p>\n<p>Most Linux&#8217;s have SELinux installed by default and this gives an error when the installer does not take care of the Selinux policy&#8217;s. The error is as follows:<\/p>\n<p>500 OOPS: cannot change directory:\/home\/someuser<\/p>\n<p>vi \/etc\/selinux\/config<\/p>\n<p>SELINUX=disabled<\/p>\n<p>Setting SELinux for ftp access:<\/p>\n<p>getsebool -a | grep ftp<\/p>\n<p>setsebool -P ftp_home_dir on<\/p>\n<p>chkconfig &#8211;levels 345 vsftpd on<\/p>\n<p>service vsftpd start<\/p>\n<p>The virtual users home folders will be under \/var\/ftp\/. You need to have either &#8216;su&#8217; permissions or &#8216;root&#8217; access or &#8216;sudo&#8217; access.<\/p>\n<p>As authentication will be required pam_userdb is a good option and is installed by default. Check with:<\/p>\n<p>yum info db4-utils<\/p>\n<p>yum install db4-utils as necessary<\/p>\n<p>Now cd to \/etc\/vsftpd and prepare the .txt user file with the usernames and passwords.<br \/>\nThis file will have a username in single line and the password in the next as shown. It is good practice to put these in a separate folder.<\/p>\n<p>cd \/etc\/vsftpd<br \/>\nmkdir vuser<br \/>\ncd vuser<br \/>\nvim vuser_list<\/p>\n<p>sudhakar<br \/>\npassword1<br \/>\nbellamkonda<br \/>\npassword2<\/p>\n<p>db_load -T -t hash \/etc\/vsftpd\/vuser\/vuser_list \/etc\/vsftpd\/vuser\/vuser_db.db<\/p>\n<p>vi \/etc\/pam.d\/vsftpd <\/p>\n<p>cd \/etc\/pam.d\/<br \/>\nvi vsftpd<\/p>\n<p>auth     sufficient pam_userdb.so db=\/etc\/vsftpd\/vuser\/vuser_db<br \/>\naccount  sufficient pam_userdb.so db=\/etc\/vsftpd\/vuser\/vuser_db<\/p>\n<p>vi \/etc\/vsftpd\/vsftpd.conf<\/p>\n<p>guest_enable=YES # activate the virtual users<br \/>\nvirtual_use_local_privs=YES # virtual users have local priveleges<br \/>\nuser_sub_token=$USER<br \/>\nlocal_root=\/var\/ftp\/vuser\/$USER # specifies a home directory for each virtual user<br \/>\nchroot_local_user=YES # Restricting the user to the FTP area and HOME dir&#8217;s only<\/p>\n<p>Create the Virtual User Folders<\/p>\n<p>cd \/var\/ftp<br \/>\nmkdir vuser<br \/>\nmkdir vuser\/sudhakar<br \/>\nmkdir vuser\/bellamkonda<br \/>\nchown -R ftp:ftp \/etc\/ftp\/vuser\/<\/p>\n<p>\/var\/ftp\/vuser\/<\/p>\n<p>mkdir yourlocaluser<br \/>\nchown ftp:ftp yourlocaluser<\/p>\n<p>ln -s \/var\/ftp\/vuser\/yourlocaluser \/home\/yourlocaluser\/ftphome<\/p>\n<p>service vsftpd start<br \/>\nservice vsftpd restart<\/p>\n<p>cd \/etc\/vsftpd<br \/>\nmkdir vuser<\/p>\n<p>vuserchk &#8211; checks the necessary files and folders necessary for these scripts<br \/>\nvuser.conf &#8211; the file containing configuration parameters for these scripts<br \/>\nvuseradd &#8211; adds a virtual user<br \/>\nvuserdel &#8211; delets a virtual user<br \/>\nvuserres &#8211; restores a deleted user<br \/>\nvuserpas &#8211; changes a virtual user password<br \/>\nvusersho &#8211; displays the user password<\/p>\n<p>vsftpd SSL <\/p>\n<p>yum install vsftpd<\/p>\n<p>openssl req -x509 -nodes -days 365 -newkey rsa:1024 \\<br \/>\n -keyout \/etc\/vsftpd\/vsftpd.pem \\<br \/>\n -out \/etc\/vsftpd\/vsftpd.pem<\/p>\n<p>Configure vsftpd<\/p>\n<p>To configure vsftpd you edit the file \/etc\/vsftpd\/vsftpd.conf and add the following lines:<\/p>\n<p> ssl_enable=YES<br \/>\n allow_anon_ssl=NO<br \/>\n force_local_data_ssl=NO<br \/>\n force_local_logins_ssl=NO<br \/>\n ssl_tlsv1=YES<br \/>\n ssl_sslv2=NO<br \/>\n ssl_sslv3=NO<br \/>\n rsa_cert_file=\/etc\/vsftpd\/vsftpd.pem<\/p>\n<p>\/etc\/rc.d\/init.d\/vsftpd restart<\/p>\n<p>FTP Security &#8211; Chroot \/ Jail user (limiting user to own their home directory only)<\/p>\n<p>Step1: Editing \/etc\/vsftpd\/vsftpd.conf.<\/p>\n<p>Option A: chroot all local user<\/p>\n<p>By default, if you are adding in chroot_local_user=YES .All the local users are&#8217; chroot()&#8217; \/jailed to their \/home\/user direcory. Go to last line adding in the line<br \/>\nvim \/etc\/vsftpd\/vsftpd.conf<\/p>\n<p>chroot_local_user=YES<\/p>\n<p>Option B: chroot only selected users<\/p>\n<p>If you want only selected ftp user restricted to their home directory, uncomment\/delete the # sign at line  94 and 96. If chroot_local_user=YES  was previously added , make sure that chroot_local_user=YES is removed from your vsftpd.conf file.<br \/>\nvim \/etc\/vsftpd\/vsftpd.conf<\/p>\n<p>91 # You may specify an explicit list of local users to chroot() to their home<br \/>\n92 # directory. If chroot_local_user is YES, then this list becomes a list of<br \/>\n93 # users to NOT chroot().<br \/>\n94  chroot_list_enable=YES<br \/>\n95 # (default follows)<br \/>\n96 chroot_list_file=\/etc\/vsftpd\/chroot_list<\/p>\n<p>CentOS Linux FTP Server<\/p>\n<p>FTP Security &#8211; Chroot \/ Jail user (limiting user to own their home directory only)<\/p>\n<p>Local account ftp user has the rights to change to any directory outside from their \/home\/user by default. Therefore, they can browse any files in any directory in FTP servers. Let&#8217;s have a close look at the example below. The user james is browsing the \/etc\/sysconfig\/networking directory and he knows that there are two directories which is devices and profiles. If james has rights on the file outside his \/home directory(such as group rights), he can just download these files.<br \/>\n>C:\\>ftp 192.168.13.145<br \/>\nConnected to 192.168.13.145.<br \/>\n220 (vsFTPd 2.0.5)<br \/>\nUser (192.168.13.145:(none)): james<br \/>\n331 Please specify the password.<br \/>\nPassword:<br \/>\n230 Login successful.<br \/>\nftp> pwd<br \/>\n257 &#8220;\/home\/james&#8221;<br \/>\nftp> cd \/etc\/sysconfig\/networking<br \/>\n250 Directory successfully changed.<br \/>\nftp> pwd<br \/>\n257 &#8220;\/etc\/sysconfig\/networking&#8221;<br \/>\nftp> ls<br \/>\n200 PORT command successful. Consider using PASV.<br \/>\n150 Here comes the directory listing.<br \/>\ndevices<br \/>\nprofiles<br \/>\n226 Directory send OK.<br \/>\nftp: 19 bytes received in 0.00Seconds 19.00Kbytes\/sec.<br \/>\nftp> bin<br \/>\n200 Switching to Binary mode.<br \/>\nftp> cd devices<br \/>\n250 Directory successfully changed.<br \/>\nftp> ls<br \/>\n200 PORT command successful. Consider using PASV.<br \/>\n150 Here comes the directory listing.<br \/>\nifcfg-eth0<br \/>\nifcfg-eth0.bak<br \/>\nifcfg-eth1<br \/>\nifcfg-eth1.bak<br \/>\n226 Directory send OK.<br \/>\nftp: 56 bytes received in 0.00Seconds 28.00Kbytes\/sec.<br \/>\nftp> get ifcfg-eth0<br \/>\n200 PORT command successful. Consider using PASV.<br \/>\n150 Opening BINARY mode data connection for ifcfg-eth0 (117 bytes).<br \/>\n226 File send OK.<br \/>\nftp: 117 bytes received in 0.00Seconds 117.00Kbytes\/sec.<\/p>\n<p>Thus, its always recommended to jail\/ restrict FTP user access only to their \/home\/user direcotory.<\/p>\n<p>Step1: Editing \/etc\/vsftpd\/vsftpd.conf.<\/p>\n<p>Option A: chroot all local user<\/p>\n<p>By default, if you are adding in chroot_local_user=YES .All the local users are&#8217; chroot()&#8217; \/jailed to their \/home\/user direcory. Go to last line adding in the line<br \/>\nvim \/etc\/vsftpd\/vsftpd.conf<\/p>\n<p>chroot_local_user=YES<\/p>\n<p>Option B: chroot only selected users<\/p>\n<p>If you want only selected ftp user restricted to their home directory, uncomment\/delete the # sign at line  94 and 96. If chroot_local_user=YES  was previously added , make sure that chroot_local_user=YES is removed from your vsftpd.conf file.<br \/>\nvim \/etc\/vsftpd\/vsftpd.conf<\/p>\n<p>91 # You may specify an explicit list of local users to chroot() to their home<br \/>\n92 # directory. If chroot_local_user is YES, then this list becomes a list of<br \/>\n93 # users to NOT chroot().<br \/>\n94  chroot_list_enable=YES<br \/>\n95 # (default follows)<br \/>\n96 chroot_list_file=\/etc\/vsftpd\/chroot_list<\/p>\n<p>Step2 (if selected option B above): create a file named chroot_list under \/etc\/vsftpd\/<\/p>\n<p>The following example, we are creating chroot_list and insert the user james in the list<br \/>\ncd \/etc\/vsftpd\/<\/p>\n<p>vim chroot_list<\/p>\n<p>james<\/p>\n<p>Step3: Restart vsFTPD services<br \/>\nservice vsftpd restart<br \/>\nShutting down vsftpd: [ OK ]<br \/>\nStarting vsftpd for vsftpd: [ OK ]<\/p>\n","protected":false},"excerpt":{"rendered":"<p>CentOS 6<\/p>\n<p>vsftpd 2.2.2<\/p>\n<p>su &#8211; root<\/p>\n<p>yum install vsftpd<\/p>\n<p>cd \/etc\/vsftpd\/<\/p>\n<p>vi config<\/p>\n<p>anonymous_enable=NO This is set to YES by default.<\/p>\n<p>local_enable=YES This is set to NO by default and change when you want the local users to have ftp access.<\/p>\n<p>xferlog_enable=Yes This is set to NO by default. Your logs will be written [&#8230;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[14],"tags":[],"_links":{"self":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/194"}],"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=194"}],"version-history":[{"count":3,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/194\/revisions"}],"predecessor-version":[{"id":197,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/194\/revisions\/197"}],"wp:attachment":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=194"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=194"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=194"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}