Sunday, January 11, 2015

How to Setup Vsftpd server and Point the Home Directory manually



FTP is used to transfer files from one host to another over TCP network. There are 3 popular FTP server packages available PureFTPD, VsFTPD and ProFTPD. 

If you are login as a normal user, you have to use "sudo" before the command, only for the first time. If your in root login, you can simply use the command, without "sudo".

Step 1 » Update your repositories.
     root@digidom:~# apt-get update

Step 2 » Install VsFTPD package using the below command.
     root@digidom:~# apt-get install vsftpd

Step 3 » Check the vsftpd directories and file paths.
     root@digidom:~# whereis vsftpd


     vsftpd: /usr/sbin/vsftpd /etc/vsftpd.conf /usr/share/man/man8/vsftpd.8.gz


Step 4 » Backup the /etc/vsftpd.con file


     root@digidom:~# cp /etc/vsftpd.conf /etc/vsftpd.conf.back


Step 5 » After installation open /etc/vsftpd.conf file and make changes as follows.

     root@digidom:~# vi /etc/vsftpd.conf

     root@digidom:~# egrep -v '^#|^$' /etc/vsftpd.conf
     listen=YES
     anonymous_enable=NO
     local_enable=YES
     write_enable=YES
     dirmessage_enable=YES
     use_localtime=YES
     xferlog_enable=YES
     chroot_local_user=YES
     allow_writeable_chroot=YES
     connect_from_port_20=YES
     secure_chroot_dir=/var/run/vsftpd/empty
     pam_service_name=vsftpd
     rsa_cert_file=/etc/ssl/certs/ssl-cert-snakeoil.pem
     rsa_private_key_file=/etc/ssl/private/ssl-cert-snakeoil.key

Step 6 » Restart vsftpd service using the below command.
     root@digidom:~# service vsftpd restart


Step 7 » Create a User account with nologin shell and specify Home Directory location, I point to "/var/www/html/" and set the password. You can specify your own path.

Note : Do not delete this account using "userdel -rf mailftp". It will remove html directory, because this user (mailftp) home directory is /var/www/html/. 


  root@digidom:~# useradd -m -d /var/www/html/ -s /usr/sbin/nologin mailftp

  root@digidom:~# passwd mailftp

Options 1 » If you have any doubt in nologin shell, check the login shell.
     root@digidom:~# cat /etc/shells
          # /etc/shells: valid login shells
          /bin/sh
          /bin/dash
          /bin/bash
          /bin/rbash
          /usr/bin/tmux
          /usr/bin/screen
          /usr/sbin/nologin

If not there /usr/sbin/nologin just add for using this command.

     root@digidom:~# echo "/usr/sbin/nologin" >> /etc/shells

Step 8 » Check the user accounts details
     root@digidom:~# tail /etc/passwd | grep mailftp
          mailftp:x:1001:1001::/var/www/html/:/usr/sbin/nologin

Step 9 » Set the permission.


     root@digidom:~# chown mailftp:root /var/www/html/
     root@digidom:~# ll -d /var/www/html/
          drwxr-xr-x  5 mailftp root 4096 Dec 16 22:55 html/

                                  OR


     root@digidom:~# chown root:mailftp /var/www/html/
     root@digidom:~# chmod -R 775 /var/www/html/
     root@digidom:~# ll -d /var/www/html/
          drwxrwxr-x  5 root mailftp 4096 Dec 16 22:55 html/
     
     root@digidom:~# service vsftpd restart

Step 10 » If another option is create a directory inside of html user home directory point this.


    root@digidom:~# useradd -m -d /var/www/html/ftp -s /usr/sbin/nologin mailftp

    root@digidom:~# passwd mailftp

    root@digidom:~# chown mailftp:mailftp /var/www/html/ftp
    root@digidom:~# ll -d /var/www/html/ftp
          drwxr-xr-x  5 mailftp mailftp 4096 Dec 16 22:55 ftp/

    root@digidom:~# service vsftpd restart

That's it............

No comments:

Post a Comment