1. 程式人生 > >ubuntu服務器安裝FTP服務

ubuntu服務器安裝FTP服務

介紹 add location pub ise 版本 實現 tin fec

ubuntu服務器安裝FTP服務

[TOC]

參考教程

[ubuntu16.04搭建ftp服務器

一、實驗環境

  • 騰訊雲學生機64位ubuntu16.04
  • 騰訊雲已備案解析域名
  • 使用騰訊雲webshell登入服務器

二、安裝配置FTP

ftp服務器相比seafile網盤就簡單很多,主要問題出在配置上

下載ftp

sudo apt-get update 
sudo apt-get install vsftpd

安裝完成,輸入vsftpd -version查看版本,可以的話說明安裝成功。

配置環境

打開配置文件vim /etc/vsftpd.conf

將裏面的內容覆蓋成如下的內容:

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

裏面有幾個重要的參數

chroot_local_user=YES
chroot_list_enable=YES
chroot_list_file=/etc/vsftpd.chroot_list 
上面的這幾個配置實現的功能是:用戶被限制在自己的主目錄下。用戶名單來源於/etc/vsftpd.chroot_list。 

以及

pam_service_name=ftp原配置中為vsftpd,ubuntu用戶需要更改成ftp

其他有興趣的可以去查看其他人的相關教程有介紹

新建用戶

sudo useradd -m -s /bin/bash username -g ftp
sudo passwd seafile

然後進入用戶,

su username
cd ~

建立ftp訪問的文件pub,並給權限

mkdir pub
chmod 777 -R pub

限制用戶username只能通過ftp登陸,而不能直接登陸服務器,可以返回ubuntu賬戶或者root賬戶操作

sudo  usermod -s /sbin/nologin username

新建/etc/vsftpd.chroot_list,並將username加入進去

之後啟動或者重啟vsftpd即可

 /etc/init.d/vsftpd restart
 /etc/init.d/vsftpd start

然後在文件管理器那邊輸入 ftp:www.你的域名,然後輸入用戶名和密碼。

大功告成!

ubuntu服務器安裝FTP服務