Simple set up and configure the FTP server under Linux

I. Introduction

Network security needs to set up an FTP server experiment 5 experiment, after into some pit, or record under construction and configuration process, we hope others can avoid detours.
Under this article to install and configure Linux FTP performed at VMware in Ubuntu 16, for CentOS Linux and other systems do not apply, install other systems need to refer to other articles.
Also note that permission issues, some commands require sudo [original command] before execution, so here basically use the sudo.
The following is the text


Second, the basic installation

1. Install the ftp server

Run the following command

sudo apt-get update 
sudo apt-get install vsftpd 
#这里遇到了问题1,解决方案在最下面。

After the command can be used vsftpd --versionto detect whether the installation version is already installed.

2. Configure the ftp server
(1) Before modifying the configuration files to back up, back up series of commands.

sudo cp /etc/vsftpd.conf /etc/vsftpd_bk.conf

(2) modify the configuration file

Vim may be used, may be used to enter editing gedit, I feel gedit operation is relatively simple, and therefore used herein gedit. (Command 2 is selected from the following 1)

Use sudo vim /etc/vsftpd.conforsudo gedit /etc/vsftpd.conf

(3) the contents of the configuration file

I was here in the configuration file vsftpd.conf as follows (For a more in-depth requirements, after modifying the configuration file), where only a simple configuration of the case.

listen=NO
listen_ipv6=YES

# Allow anonymous FTP? (Disabled by default).
anonymous_enable=NO

# Uncomment this to allow local users to log in.
local_enable=YES

# Uncomment this to enable any form of FTP write command.
write_enable=YES

# Default umask for local users is 077. You may wish to change this to 022,
# if your users expect that (022 is used by most other ftpd's)
local_umask=022

# Activate directory messages - messages given to remote users when they
# go into a certain directory.
dirmessage_enable=YES
#
# If enabled, vsftpd will display directory listings with the time
# in  your  local  time  zone.  The default is to display GMT. The
# times returned by the MDTM FTP command are also affected by this
# option.
use_localtime=YES
#
# Activate logging of uploads/downloads.
xferlog_enable=YES
#
# Make sure PORT transfer connections originate from port 20 (ftp-data).
connect_from_port_20=YES

# You may override where the log file goes if you like. The default is shown
# below.
xferlog_file=/var/log/vsftpd.log
#
# If you want, you can have your log file in standard ftpd xferlog format.
# Note that the default log file location is /var/log/xferlog in this case.
xferlog_std_format=YES


# You may fully customise the login banner string:
ftpd_banner=Welcome to FTP service.


# You may specify an explicit list of local users to chroot() to their home
# directory. If chroot_local_user is YES, then this list becomes a list of
# users to NOT chroot().
# (Warning! chroot'ing can be very dangerous. If using chroot, make sure that
# the user does not have write access to the top level directory within the
# chroot)
chroot_local_user=YES
chroot_list_enable=YES
# (default follows)
chroot_list_file=/etc/vsftpd.chroot_list

# This option should be the name of a directory which is empty.  Also, the
# directory should not be writable by the ftp user. This directory is used
# as a secure chroot() jail at times vsftpd does not require filesystem
# access.
secure_chroot_dir=/var/run/vsftpd/empty
#
# This string is the name of the PAM service vsftpd will use.
# pam_service_name=vsftpd
pam_service_name=ftp

# This option specifies the location of the RSA certificate to use for SSL
# encrypted connections.
rsa_cert_file=/etc/ssl/certs/ssl-cert-snakeoil.pem
rsa_private_key_file=/etc/ssl/private/ssl-cert-snakeoil.key
ssl_enable=NO

#
# Uncomment this to indicate that vsftpd use a utf8 filesystem.
utf8_filesystem=YES

Note Ctrl + s to save.
For the terminal temporary warning can be ignored (usually not a big problem).


Third, add users

Here to add users t1, for example, other users can add names the same way.

1. first create a user name in the directory / home

sudo mkdir /home/t1

2. Then bind the user login directory and shell

-D directory specified in the command later when the user logs in, -s specifies the user login shell after use
sudo useradd -d /home/t1 -s /bin/bash t1

3. Add the user's password t1

sudo passwd t1
After setting up their own password

4. Set the owner / home / t1 is t1

sudo chown t1:t1 /home/t1

5. Add the user to /etc/vsftpd.user_list

Add the following command to open the file in a row, says t1 (that is, your new user name), save and exit.
sudo gedit /etc/vsftpd.user_list
FIG file follows
.Png file contents

6. Add the user to /etc/vsftpd.chroot_list, add the contents of the line are also t1, similar to the previous step.

sudo gedit /etc/vsftpd.chroot_list

The last attempt to restart the service
systemctl restart vsftpd
basic configuration is complete


Fourth, the test

1.Ubuntu local testftp localhost

localhost test .png

2.Windows test:
(1) cmd in: ftp IP地址

cmd test .png

(2) the address bar

It can also be in the address bar ftp:IP地址or ftp://IP地址/view.

Address bar 1.png

After entering the correct user name and password appears

Address bar 2.png

Folder is empty, because we have not created the file.

3.Ubuntu new file after the test:

Create a new file in Ubuntu

cd /home/t1
sudo gedit test.txt

Enter the following exit

New .png file contents

Then look in the windows

windows2.png

Open txt get

Get txt.png

Successfully built a simple FTP server


Fifth, the problems encountered

1. sudo apt-get updatecommand after the following problems occur.
E: 无法获得锁 /var/lib/dpkg/lock-frontend - open (11: 资源暂时不可用)
E: 无法获取 dpkg 前端锁 (/var/lib/dpkg/lock-frontend),是否有其他进程正占用它?

solve:

sudo rm /var/cache/apt/archives/lock
sudo rm /var/lib/dpkg/lock-frontend

If after:

E: 无法获得锁 /var/lib/dpkg/lock - open (11: 资源暂时不可用)
E: 无法锁定管理目录(/var/lib/dpkg/),是否有其他进程正占用它?

then:

sudo rm /var/lib/dpkg/lock

The whole process follows the successful resolution:
Solve .png

2. No

Guess you like

Origin www.cnblogs.com/LieDra/p/12016124.html