使用 ftp 访问我的云 VPS ubuntu 解决方案时遇到了实际问题。
我尝试过 vsftpd 和 pure-ftpd。我发现两者都有局限性。现在我尝试专注于 vsftpd,因为它广受好评。
我尝试按照此处的说明进行操作:
http://ubuntuforums.org/showthread.php?t=518293
我唯一没有到目前为止,本指南中所做的就是添加 TLS/SSL/FTPS 规则,因为我在将端口 990 添加到服务器的防火墙设置时遇到了问题。我已向提供商反映此问题,希望能及时解决。
最初我使用的是具有 shell 访问权限的用户。这允许用户登录并访问服务器和正确的文件夹,但无法写入新文件或覆盖服务器上的现有文件。他们可以创建文件夹和删除文件。当我使用命令行 ftp 使用 shell 帐户登录时,我可以毫无问题地将文件写入 (mput) 到服务器,但我认为这是因为命令行 ftp 的工作方式与 ftp 服务不同。
我认为我的问题可能是我的用户可能无法访问,因为他们有 shell 访问权限。然后我创建了一个没有 shell 访问权限的新用户。我无法使用这些用户登录。我收到 530 登录错误,尽管我已经更改并测试了密码。我也无法使用命令行 ftp 登录。
我已将我的 vsftpd.conf 文件包含在下面。我尝试了一个自定义文件,但最终还是恢复到了原来的文件,只能重新开始。我已添加 check_shell=NO 指令,看看这是否有帮助。我已开始尝试向系统添加虚拟用户,但我不知道这会有什么改变。
我确实花了整个周末试图解决这个问题,但无济于事。
以下是 /etc/shadow 内容 (-hashed pwds)。两个新用户是 spdftp 和 scftp:
root:xxxx:15607:0:99999:7:::
daemon:*:15104:0:99999:7:::
bin:*:15104:0:99999:7:::
sys:*:15104:0:99999:7:::
sync:*:15104:0:99999:7:::
games:*:15104:0:99999:7:::
man:*:15104:0:99999:7:::
lp:*:15104:0:99999:7:::
mail:*:15104:0:99999:7:::
news:*:15104:0:99999:7:::
uucp:*:15104:0:99999:7:::
proxy:*:15104:0:99999:7:::
www-data:*:15104:0:99999:7:::
backup:*:15104:0:99999:7:::
list:*:15104:0:99999:7:::
irc:*:15104:0:99999:7:::
gnats:*:15104:0:99999:7:::
nobody:*:15104:0:99999:7:::
libuuid:!:15104:0:99999:7:::
syslog:*:15104:0:99999:7:::
sshd:*:15104:0:99999:7:::
mysql:!:15104:0:99999:7:::
postfix:*:15424:0:99999:7:::
clamav:!:15425:0:99999:7:::
amavis:*:15425:0:99999:7:::
vmail:!:15425:0:99999:7:::
dovecot:*:15425:0:99999:7:::
vsftpd:!:15724:0:99999:7:::
ftpuser:!:15752:0:99999:7:::
ftp:*:15752:0:99999:7:::
spdftp:xxxx:15754:0:99999:7:::
scftp:xxxx:15754:0:99999:7:::
以下是这些用户的 /etc/passwd 文件的输出:
spdftp:x:5005:1002::/var/www/path/to/home:/bin/sh
scftp:x:5006:1002::/var/www/path/to/home:/bin/sh
为了记录,我使用了以下命令:
useradd scftp -d /path/to/home/dir -g ftpusers
创建用户。我没有添加 shell 参数,尽管系统将其设置为 /bin/sh。
我 chown -Rf /var/www spdftp 和 chown -Rf /var/www/path/to/home scftp(我希望用户 spdftp 成为一种主 ftp 帐户,而 scftp 只能访问特定的站点文件夹)。我还 chgrp -Rf /var/www ftpusers
/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.
#
# READ THIS: This example file is NOT an exhaustive list of vsftpd options.
# Please read the vsftpd.conf.5 manual page to get a full idea of vsftpd's
# capabilities.
#
# Allow anonymous FTP? (Beware - allowed by default if you comment this out).
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
# Ignore shell login request
check_shell=NO
#
# 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
#
# Uncomment this to allow the anonymous FTP user to upload files. This only
# has an effect if the above global write enable is activated. Also, you will
# obviously need to create a directory writable by the FTP user.
#anon_upload_enable=YES
#
# Uncomment this if you want the anonymous FTP user to be able to create
# new directories.
#anon_mkdir_write_enable=YES
#
# Activate directory messages - messages given to remote users when they
# go into a certain directory.
dirmessage_enable=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
#
# If you want, you can arrange for uploaded anonymous files to be owned by
# a different user. Note! Using "root" for uploaded files is not
# recommended!
#chown_uploads=YES
#chown_username=whoever
#
# 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 change the default value for timing out an idle session.
#idle_session_timeout=600
#
# You may change the default value for timing out a data connection.
#data_connection_timeout=120
#
# It is recommended that you define on your system a unique user which the
# ftp server can use as a totally isolated and unprivileged user.
#nopriv_user=ftpsecure
#
# Enable this and the server will recognise asynchronous ABOR requests. Not
# recommended for security (the code is non-trivial). Not enabling it,
# however, may confuse older FTP clients.
#async_abor_enable=YES
#
# By default the server will pretend to allow ASCII mode but in fact ignore
# the request. Turn on the below options to have the server actually do ASCII
# mangling on files when in ASCII mode.
# Beware that on some FTP servers, ASCII support allows a denial of service
# attack (DoS) via the command "SIZE /big/file" in ASCII mode. vsftpd
# predicted this attack and has always been safe, reporting the size of the
# raw file.
# ASCII mangling is a horrible feature of the protocol.
#ascii_upload_enable=YES
#ascii_download_enable=YES
#
# You may fully customise the login banner string:
#ftpd_banner=Welcome to blah FTP service.
#
# You may specify a file of disallowed anonymous e-mail addresses. Apparently
# useful for combatting certain DoS attacks.
#deny_email_enable=YES
# (default follows)
#banned_email_file=/etc/vsftpd.banned_emails
#
# 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
#
# You may activate the "-R" option to the builtin ls. This is disabled by
# default to avoid remote users being able to cause excessive I/O on large
# sites. However, some broken FTP clients such as "ncftp" and "mirror" assume
# the presence of the "-R" option, so there is a strong case for enabling it.
#ls_recurse_enable=YES
#
# When "listen" directive is enabled, vsftpd runs in standalone mode and
# listens on IPv4 sockets. This directive cannot be used in conjunction
# with the listen_ipv6 directive.
listen=YES
#
# This directive enables listening on IPv6 sockets. To listen on IPv4 and IPv6
# sockets, you must run two copies of vsftpd with two configuration files.
# Make sure, that one of the listen options is commented !!
#listen_ipv6=YES
pam_service_name=ftp
我不太确定最后一行。我认为应该是 pam_service_name=vsftpd,但无论如何都没有用。
我还创建了 vsftpd.chroot_list。以下是该文件的内容:
spdftp
scftp
有一个 /etc/vsftpd.passwd 文件,但是它没有这两个用户名的条目。如果这是问题所在,我不知道如何创建或添加它们。
任何帮助都将不胜感激。我的头发很少,剩下的头发我都拔掉了!
更新
我将每个用户的 shell 更改为第一个 /bin/false 和第二个 /bin/bash。这至少允许我登录,而不会收到 530 登录错误错误。但在此之后我收到网络超时错误,日志中出现以下内容(xxxx 是我的固定 IP 地址):
Mon Feb 18 11:49:15 2013 [pid 2] CONNECT: Client "x.x.x.x"
Mon Feb 18 11:49:15 2013 [pid 1] [scftp] OK LOGIN: Client "x.x.x.x"
Mon Feb 18 11:50:48 2013 [pid 2] CONNECT: Client "x.x.x.x"
Mon Feb 18 11:50:49 2013 [pid 1] [spdftp] OK LOGIN: Client "x.x.x.x"
/var/log/vsftpd.log 中似乎没有给出任何失败原因。不确定是否还有其他日志可以检查。
更新2
我发现我在 vsftpd.conf 文件中遗漏了几行:
#guest_enable=YES
#guest_username=ftp
#user_config_dir=/etc/vsftpd/vusers
当我开始创建虚拟用户时,我以为我已经注释掉了它,但实际上并没有。
现在我可以连接了,最后一个问题是我又回到了原点,我的用户无法将文件上传到服务器。我的 vsftpd.log 中出现以下错误:
Mon Feb 18 12:13:54 2013 [pid 3] [spdftp] FAIL CHMOD: Client "x.x.x.x", "/path/to/home/folder/2013/humans.txt 777"
那么,又回到了同一个问题。有人有事吗?
答案1
不管怎样,我通过彻底清除 vsftpd 服务和安装,然后重新安装,解决了这个问题。一定是我的 vsftpd 设置出现了交叉或冲突。我之前卸载过,但不知道:
aptitude purge vsftpd
aptitude autoclean
有一次我这样做了,然后又做了
aptitude install vsftpd
我在 vsftpd.conf 中需要更改的唯一设置是 write_enable=YES。(我还添加了一些设置以确保用户无法离开他们的主文件夹)。