0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

ubuntu vsftpd 530 Login incorrect

Last updated at Posted at 2021-08-27

ubuntu 安装 vsftpd 一般使用:

sudo apt install vsftpd

vsftp 配置

listen=YES
listen_ipv6=NO
anonymous_enable=NO
local_enable=YES
write_enable=YES
dirmessage_enable=YES
use_localtime=YES
connect_from_port_20=YES
chroot_local_user=YES
pam_service_name=vsftpd
xferlog_enable=YES
xferlog_file=/var/log/vsftpd.log
xferlog_std_format=YES
user_sub_token=$USER
local_root=/home/$USER/ftp
pasv_min_port=50000
pasv_max_port=50010
# 全部用户被限制在主目录
chroot_local_user=YES
# 启用例外用户名单
chroot_list_enable=YES
# 指定例外用户列表文件,列表中用户不被锁定在主目录
chroot_list_file=/etc/vsftpd/chroot_list
# 开启被动模式
pasv_enable=YES
# 公网IP
pasv_address=1.1.1.1

在账号、密码、主目录都是正确的情况下,可能会遇到账号登录提示 530 Login incorrect 的问题。

网络上有好多解决方案,例如修改/etc/vsftpd.conf文件,将pam_service_name=vsftpd 修改为 pam_service_name=ftp ,虽然能够解决这个问题,但是这种方法其实是错误的。这样由于/etc/pam.d/ftp 文件不存在,等于是绕过了 PAM。

vsftpd pam 文件分析

# /etc/pam.d/vsftpd
# Standard behaviour for ftpd(8).
auth	required	pam_listfile.so item=user sense=deny file=/etc/ftpusers onerr=succeed

# Note: vsftpd handles anonymous logins on its own. Do not enable pam_ftp.so.

# Standard pam includes
@include common-account
@include common-session
@include common-auth
auth	required	pam_shells.so

可能导致 530 错误的有:
auth required pam_listfile.so item=user sense=deny file=/etc/ftpusers onerr=succeedauth required pam_shells.so

auth required pam_listfile.so item=user sense=deny file=/etc/ftpusers onerr=succeed
该配置项的含义是 /etc/ftpusers 中的用户禁止登陆,如果文件不存在在默认所有用户均允许登录. 所以确保用户没在这个文件内。

auth required pam_shells.so 配置项的含义为仅允许用户的 shell 为 /etc/shells
文件内的 shell 命令时,才能够成功。

cat /etc/shells

# /etc/shells: valid login shells
/bin/sh
/bin/bash
/bin/rbash
/bin/dash

而创建 ftp 用户时,为了禁止 ssh 登录,一般多为/bin/false 、/usr/sbin/nologin 等,显然不是一个有效的 bash,也就无法登录了。

解决方案

  1. 查看/etc/ftpusers,确保账号没有在这个文件内。
  2. 修改/etc/pam.d/vsftpd
    auth required pam_shells.so 修改为-> auth required pam_nologin.so 即可
  3. 重启 vsftpd

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?