如何使用阿里云主机(Ubuntu)搭建FTP服务器(超详细)

由于需要上传代码文件,又不能直接给所有SSH来连接,于是只能搭建个ftp服务器了,记录整个过程。

1、安装vsftpd

sudo apt-get install vsftpd

2、sudo vi /etc/vsftpd.conf并写入如下

# Example config file /etc/vsftpd.conf
#
# The default compiled in settings are fairly paranoid. This sample file
# loosens things up a bit, to make the ftp daemon more usable.
# Please see vsftpd.conf.5 for all compiled in defaults.
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                                          

3、重启服务

systemctl restart vsftpd.service

设置开机自启动

systemctl enable vsftpd.service

4、创建共享文件夹

mkdir /home/myftp

给这个文件夹所有权限

chmod 777 -R /home/myftp

5、创建用户byk和密码

sudo useradd -d /home/myftp/ -s /bin/bash byk

设置密码

sudo passwd byk

输入密码,然后

sudo vi /etc/vsftpd.chroot_list把用户byk写入,重启服务。

注意,想要put文件必须给这个文件所有权限,不然会报错,put是ftp的命令,即上传文件的意思,具体命令使用请自查。

6、开放阿里云主机ftp运行的端口

netstat -atunp | grep ftp查看ftp端口为21,于是去开放21端口。

7、使用windows远程连接

打开internet选项->高级->使用被动FTP去掉勾,保存

在文件浏览器地址栏输入ip

输入密码

ok,可以愉快地使用ftp了。

猜你喜欢

转载自blog.csdn.net/weixin_42363997/article/details/84439218