The installation part is taken from Open Source China, and finally the red part solves the problem of unable to log in (cannot change directory)
The environment is centos6 to install vsftpd The
first step: install vsftpd, allow it in the terminal
# yum -y install vsftpd
No problem, just install it
Step 2: Edit the configuration file of vsftpd
# vi /etc/vsftpd/vsftpd.conf
Step 3: Empty the file, then add the following:
listen=YES
background=YES
anonymous_enable=NO
local_enable=YES
write_enable=YES
local_umask=022
anon_upload_enable=NO
anon_mkdir_write_enable=NO
dirmessage_enable=YES
xferlog_enable=YES
connect_from_port_20=YES
chown_uploads=NO
xferlog_file=/var/log/vsftpd.log
xferlog_std_format=YES
async_abor_enable=YES
ascii_upload_enable=YES
ascii_download_enable=YES
ftpd_banner=Welcome to hao32 FTP servers
pam_service_name=vsftpd
chroot_local_user=NO
chroot_list_enable=YES
chroot_list_file=/etc/vsftpd/vsftpd.chroot_list
Step 4: Run the following command in the terminal
# touch /etc/vsftpd/vsftpd.chroot_list
# service vsftpd start
If the following sentence appears:
Starting vsftpd for vsftpd: [ OK ]
则表示成功,如果不行则用这个语句:
/etc/rc.d/init.d/xinetd restart
ftp默认我们使用系统用户, 现在我们来添加用户ftptest, 指向目录/home/ftptest , 权限是nologin, 就是没给shell权限, 不影响ftp的
# useradd ftptest -d /home/ftptest -s /sbogin
如果显示:in/nol
useradd: warning: the home directory already exists.
Not copying any file from skel directory into it.
不用理会, 只是告诉你, 你指向的目录已经存在了, 这不影响
设置目录及其文件的属组, 你也可以使用别的分组方式
# chown -R ftptest . ftptest /home/ftptest
设置一下用户hao32的密码, 自定义啦
# passwd ftptest
把用户 ftptest 加到/etc/vsftpd/vsftpd.chroot_list里, 这样用户就可以正常登陆并且不能跳出自己的目录
# echo ‘ ftptest ′ >> /etc/vsftpd/vsftpd.chroot_list
# service vsftpd restart
测试登陆
ftp主机: 服务器IP地址
ftp用户: ftptest
ftp密码: ftptest
如果这个时候遇到 cannot change directory /home/ftptest
请输入以下命令 # setsebool -P allow_ftpd_full_access 1
# service vsftpd restart
这个时候如果再遇到 java.net.SocketTimeoutException: Read timed out
或者类似超时问题
解决方法
来源 : http://www.lingdus.com/forum.php?mod=viewthread&tid=8189
在服务端配置被动模式就可以从根源上解决这问题。
1、编辑 Vsftpd 配置文件
2、在最下面添加以下信息
3、加载内核 ip_conntrack_ftp 和 ip_nat_ftp(终端执行)
4、配置 iptables 开放 4000 到 5000 端口
5、加载 iptables 配置
6、重启 Vsftpd