Ubuntu14.04 vsftpd
參考文檔:
http://www.cnblogs.com/acpp/archive/2010/02/08/1666054.html
http://segmentfault.com/a/1190000000438443
Vsftpd虛擬用戶設置
一.安裝
apt-get -y install vsftpd
root@localhost:~# lsb_release -a 2>/dev/null
Distributor ID:
Ubuntu
Description:
Ubuntu 14.04.1 LTS
Release:
14.04
Codename:
trusty
root@localhost:~# vsftpd -v
vsftpd: version
3.0.2
root@localhost:/usr/share/doc/vsftpd/examples# pwd
/usr/share/doc/vsftpd/examples
root@localhost:/usr/share/doc/vsftpd/examples# ls
INTERNET_SITE
INTERNET_SITE_NOINETD
PER_IP_CONFIG
README
VIRTUAL_HOSTS
VIRTUAL_USERS
VIRTUAL_USERS_2
提示:發行版的安裝包中自帶了不少幫助文檔和配置範例,很是有情懷
二.匿名用戶
cp /etc/vsftpd.conf{,.default}
養成修改前作備份的習慣
1.開啓匿名訪問
anonymous_enable=YES #匿名訪問只須要對默認的配置文件修改上面一行便可,但只能讀
root@localhost:~# touch /srv/ftp/Test2015
root@localhost:~# ftp localhost
ftp: connect to address ::1: Connection refused
Trying 127.0.0.1...
Connected to localhost.
220 (vsFTPd 3.0.2)
Name (localhost:ubuntu):
ftp
331 Please specify the password.
Password:
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> pwd
257 "/"
ftp> ls
200 PORT command successful. Consider using PASV.
150 Here comes the directory listing.
-rw-r--r--
1 0
0
0 Aug 02 03:51
Test2015
226 Directory send OK.
默認的匿名用戶爲ftp或者anonymous,密碼爲空
2.修改匿名用戶的根目錄
#默認的匿名根是/srv/ftp
root@localhost:~# mkdir /ftp_guest
root@localhost:~# touch /ftp_guest/ftp
root@localhost:~# vim /etc/vsftpd.conf
anon_root=/ftp_guest
root@localhost:~# service vsftpd restart
vsftpd stop/waiting
vsftpd start/running, process 4823
root@localhost:~# ftp localhost
ftp: connect to address ::1: Connection refused
Trying 127.0.0.1...
Connected to localhost.
220 (vsFTPd 3.0.2)
Name (localhost:ubuntu): ftp
331 Please specify the password.
Password:
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> pwd
257 "/"
ftp> ls
200 PORT command successful. Consider using PASV.
150 Here comes the directory listing.
-rw-r--r--
1 0
0
0 Aug 02 03:49 ftp
226 Directory send OK.
三.本地用戶
1.本地用戶全局FTP根目錄
root@localhost:~# mkdir -p /ftp_admin/{leader,foo}
root@localhost:~# vim /etc/vsftpd.conf
root@localhost:~# useradd -M -s /bin/false leader
root@localhost:~# echo leader:leader|chpasswd
問題1:密碼輸入正確了仍然提示密碼不對
注意:ubuntu登陸shell設置爲/bin/false或/usr/sbin/nologin都會提示incorrect,按照rhel的模式來配置會有問題
root@localhost:~# ftp localhost
ftp: connect to address ::1: Connection refused
Trying 127.0.0.1...
Connected to localhost.
220 (vsFTPd 3.0.2)
Name (localhost:ubuntu): leader
331 Please specify the password.
Password:
530 Login incorrect.
Login failed.
ftp> 221 Goodbye.
問題2:提示不能切換到家目錄
root@localhost:~# chsh -s /bin/bash leader
root@localhost:~# ftp localhost
ftp: connect to address ::1: Connection refused
Trying 127.0.0.1...
Connected to localhost.
220 (vsFTPd 3.0.2)
Name (localhost:ubuntu): leader
331 Please specify the password.
Password:
500 OOPS: cannot change directory:/home/leader
Login failed.
421 Service not available, remote server has closed connection
解決辦法1:修改/etc/passwd把對應家目錄的欄位補全爲合法的目錄(實際存在的目錄便可)
root@localhost:~# usermod leader
-d /ftp_admin/leader
root@localhost:~# ftp localhost
ftp: connect to address ::1: Connection refused
Trying 127.0.0.1...
Connected to localhost.
220 (vsFTPd 3.0.2)
Name (localhost:ubuntu): leader
331 Please specify the password.
Password:
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> pwd
257 "/ftp_admin"
ftp> ls
200 PORT command successful. Consider using PASV.
150 Here comes the directory listing.
drwxr-xr-x
2 0
0
4096 Aug 02 04:03 foo
drwxr-xr-x
2 0
0
4096 Aug 02 04:03 leader
226 Directory send OK.
這裏顯示的根在/ftp_admin是由於全局配置文件中定義的根在/ftp_admin
解決辦法2:刪除該用戶後從新建
root@localhost:~# userdel -r leader
userdel: leader mail spool (/var/mail/leader) not found
userdel: /ftp_admin/leader not owned by leader, not removing
root@localhost:~# useradd -m -s /bin/bash leader
root@localhost:~# echo leader:leader|chpasswd
root@localhost:~# ftp localhost
ftp: connect to address ::1: Connection refused
Trying 127.0.0.1...
Connected to localhost.
220 (vsFTPd 3.0.2)
Name (localhost:ubuntu): leader
331 Please specify the password.
Password:
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> pwd
257 "/ftp_admin"
ftp> ls
200 PORT command successful. Consider using PASV.
150 Here comes the directory listing.
drwxr-xr-x
2 0
0
4096 Aug 02 04:03 foo
drwxr-xr-x
2 0
0
4096 Aug 02 04:03 leader
226 Directory send OK.
2.鎖定全部本地用戶的FTP根目錄
root@localhost:~# ftp localhost
ftp: connect to address ::1: Connection refused
Trying 127.0.0.1...
Connected to localhost.
220 (vsFTPd 3.0.2)
Name (localhost:ubuntu): leader
331 Please specify the password.
Password:
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> pwd
257 "/ftp_admin"
ftp> ls
200 PORT command successful. Consider using PASV.
150 Here comes the directory listing.
drwxr-xr-x
2 0
0
4096 Aug 02 04:03 foo
drwxr-xr-x
2 0
0
4096 Aug 02 04:24 leader
226 Directory send OK.
ftp> cd ..
250 Directory successfully changed.
ftp> pwd
257 "/"
ftp> ls
200 PORT command successful. Consider using PASV.
150 Here comes the directory listing.
drwxr-xr-x
2 0
0
4096 Aug 02 01:58 bin
drwxr-xr-x
4 0
0
1024 Aug 01 19:09 boot
drwxr-xr-x
2 0
0