{"id":1667,"date":"2019-01-01T16:03:10","date_gmt":"2019-01-01T21:03:10","guid":{"rendered":"http:\/\/www.xavignu.com\/?p=1667"},"modified":"2019-01-01T16:03:12","modified_gmt":"2019-01-01T21:03:12","slug":"running-vsftpd-on-docker","status":"publish","type":"post","link":"https:\/\/www.xavignu.com\/?p=1667","title":{"rendered":"Running vsftpd on Docker"},"content":{"rendered":"\n<p>Happy 2019!!<\/p>\n\n\n\n<p>Lately I&#8217;ve been playing around with <a href=\"https:\/\/www.docker.com\/\" target=\"_blank\" rel=\"noopener\">docker<\/a> and decided to create a <a href=\"https:\/\/docs.docker.com\/engine\/reference\/builder\/\" target=\"_blank\" rel=\"noopener\">dockerfile<\/a> to have <a href=\"https:\/\/security.appspot.com\/vsftpd.html\" target=\"_blank\" rel=\"noopener\">vsftpd<\/a> running on <a href=\"https:\/\/www.centos.org\/\" target=\"_blank\" rel=\"noopener\">CentOS<\/a>. Below is my dockerfile:<\/p>\n<pre># Dockerfile for vsftpd on CentOS\nFROM centos:7\n\nMAINTAINER xavi@xavignu.com\n\nRUN yum -y update; yum -y install which vsftpd net-tools vsftpd-sysvinit; yum clean all\n\nCOPY vusers.txt \/etc\/vsftpd\/\nRUN db_load -T -t hash -f \/etc\/vsftpd\/vusers.txt \/etc\/vsftpd\/vsftpd-virtual-user.db; rm -v \/etc\/vsftpd\/vusers.txt; \\ \n\tchmod 600 \/etc\/vsftpd\/vsftpd-virtual-user.db\nCOPY vsftpd.conf \/etc\/vsftpd\/\nCOPY vsftpd.virtual \/etc\/pam.d\/\nRUN mkdir -p \/home\/vftp\/ftpuser; chown -R ftp:ftp \/home\/vftp\n\nEXPOSE 20 21\n\nCMD [\"\/usr\/sbin\/vsftpd\",\"-obackground=NO\"]\n\n<\/pre>\n\n<p>We need to create three files before building the image, one for vsftpd virtual users PAM, another vsftpd.conf file and another with the virtual users. vsftpd.conf below:<\/p>\n\n<pre>anonymous_enable=NO\nlocal_enable=YES\nvirtual_use_local_privs=YES\nwrite_enable=YES\nlocal_umask=022\npam_service_name=vsftpd.virtual\nguest_enable=YES\nuser_sub_token=$USER\nlocal_root=\/home\/vftp\/$USER\nchroot_local_user=YES\nallow_writeable_chroot=YES\nhide_ids=YES\nxferlog_enable=YES\nxferlog_file=\/var\/log\/vsftpd.log\n<\/pre>\n\n<p>Pam file, store as vsftpd.virtual<\/p>\n<pre>\n#%PAM-1.0\nauth       required     pam_userdb.so db=\/etc\/vsftpd\/vsftpd-virtual-user\naccount    required     pam_userdb.so db=\/etc\/vsftpd\/vsftpd-virtual-user\nsession    required     pam_loginuid.so\n<\/pre>\n<p>And at last a file with user and password, which we will store as vusers.txt\n<\/p>\n<pre>\nftpuser\nletmein\n<\/pre>\n\n\n\n<p>All these files shall be stored into the same directory in order for build to be successful. We proceed building.<\/p>\n<pre id=\"terminal\">docker build -t centos-vsftpd -f  centos-vsftpd . \nSending build context to Docker daemon  10.24kB\nStep 1\/10 : FROM centos:7\n ---> 1e1148e4cc2c\nStep 2\/10 : MAINTAINER xavi@xavignu.com\n ---> Using cache\n ---> cb00764989e4\nStep 3\/10 : RUN yum -y update; yum -y install which vsftpd net-tools vsftpd-sysvinit; yum clean all\n ---> Using cache\n ---> 84bc55dc256f\nStep 4\/10 : COPY vusers.txt \/etc\/vsftpd\/\n ---> Using cache\n ---> 922453bc2ba3\nStep 5\/10 : RUN db_load -T -t hash -f \/etc\/vsftpd\/vusers.txt \/etc\/vsftpd\/vsftpd-virtual-user.db; rm -v \/etc\/vsftpd\/vusers.txt; \tchmod 600 \/etc\/vsftpd\/vsftpd-virtual-user.db\n ---> Using cache\n ---> 3f0f5a3743af\nStep 6\/10 : COPY vsftpd.conf \/etc\/vsftpd\/\n ---> Using cache\n ---> f6241c5dc497\nStep 7\/10 : COPY vsftpd.virtual \/etc\/pam.d\/\n ---> b768b27a3496\nRemoving intermediate container 45326ecc02a0\nStep 8\/10 : RUN mkdir -p \/home\/vftp\/ftpuser; chown -R ftp:ftp \/home\/vftp\n ---> Running in fb940a0b999f\n ---> 8afff06f270a\nRemoving intermediate container fb940a0b999f\nStep 9\/10 : EXPOSE 20 21\n ---> Running in 0a9bd172c74e\n ---> d07e65112275\nRemoving intermediate container 0a9bd172c74e\nStep 10\/10 : CMD \/usr\/sbin\/vsftpd -obackground=NO\n ---> Running in 50f124e366ee\n ---> 0a571ecf1fed\nRemoving intermediate container 50f124e366ee\nSuccessfully built 0a571ecf1fed\nSuccessfully tagged centos-vsftpd:latest\n<\/pre>\n\n\n\n<p>We now start the vsftpd container and check its running.<\/p>\n<pre id=\"terminal\">docker run -d --name myftp centos-vsftpd:latest; docker ps \n1034cc745e43f67ae3a432ce8ebe37755b36eca2dc04f21102da2eaafe9dd832\nCONTAINER ID        IMAGE                  COMMAND                  CREATED                  STATUS                  PORTS               NAMES\n1034cc745e43        centos-vsftpd:latest   \"\/usr\/sbin\/vsftpd ...\"   Less than a second ago   Up Less than a second   20-21\/tcp           myftp\n<\/pre>\n\n\n\n<p>We connect to newly created ftp server and upload a test file.<\/p>\n<pre id=\"terminal\">ftp 172.17.0.2 \nConnected to 172.17.0.2.\n220 (vsFTPd 3.0.2)\nName (172.17.0.2:xavi): ftpuser\n331 Please specify the password.\nPassword:\n230 Login successful.\nRemote system type is UNIX.\nUsing binary mode to transfer files.\nftp> mput test.txt\nmput test.txt? y\n200 PORT command successful. Consider using PASV.\n150 Ok to send data.\n226 Transfer complete.\n10 bytes sent in 0.00 secs (187.8005 kB\/s)\nftp> \n<\/pre>\n<p>And we check the creation and content of the uploaded file.<\/p>\n<pre id=\"terminal\">docker exec myftp cat  \/home\/vftp\/ftpuser\/test.txt\nTest File\n<\/pre>\n\n\n\n<p>References:<\/p>\n<ul>\n<li><a href=\"https:\/\/help.ubuntu.com\/community\/vsftpd\" target=\"_blank\">Ubuntu vsftpd<\/a><\/li>\n<li><a href=\"https:\/\/docs.docker.com\/\" target=\"_blank\">Docker documentation<\/a><\/li>\n<\/ul>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Happy 2019!! Lately I&#8217;ve been playing around with docker and decided to create a dockerfile to have vsftpd running on CentOS. Below is my dockerfile: # Dockerfile for vsftpd on CentOS FROM centos:7 MAINTAINER xavi@xavignu.com RUN yum -y update; yum -y install which vsftpd net-tools vsftpd-sysvinit; yum clean all COPY vusers.txt \/etc\/vsftpd\/ RUN db_load -T [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"spay_email":"","jetpack_publicize_message":"","jetpack_is_tweetstorm":false,"jetpack_publicize_feature_enabled":true},"categories":[92],"tags":[106,83,105,6,104],"jetpack_featured_media_url":"","jetpack_publicize_connections":[],"jetpack_shortlink":"https:\/\/wp.me\/pTQgt-qT","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.xavignu.com\/index.php?rest_route=\/wp\/v2\/posts\/1667"}],"collection":[{"href":"https:\/\/www.xavignu.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.xavignu.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.xavignu.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.xavignu.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1667"}],"version-history":[{"count":12,"href":"https:\/\/www.xavignu.com\/index.php?rest_route=\/wp\/v2\/posts\/1667\/revisions"}],"predecessor-version":[{"id":1680,"href":"https:\/\/www.xavignu.com\/index.php?rest_route=\/wp\/v2\/posts\/1667\/revisions\/1680"}],"wp:attachment":[{"href":"https:\/\/www.xavignu.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1667"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.xavignu.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1667"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.xavignu.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1667"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}