虛擬機
vim /etc/sysconfig/selinux
修改
SELINUX=disable
reboothtml
server虛擬機的版本linux
[root@localhost ~]# hostnamectl Static hostname: n/a Transient hostname: localhost Icon name: computer-vm Chassis: vm Machine ID: 946cb0e817ea4adb916183df8c4fc817 Boot ID: 58602a448b314991b98037e3a3330feb Virtualization: kvm Operating System: Red Hat Enterprise Linux Server 7.0 (Maipo) CPE OS Name: cpe:/o:redhat:enterprise_linux:7.0:GA:server Kernel: Linux 3.10.0-123.el7.x86_64 Architecture: x86_64
vim /etc/yum.repos.d/yum.repoios
[rhel7.0]
name=rhel7.0
baseurl=http://172.25.254.22/rhel7.0
gpgcheck=0shell
yum install vsftpd -y
systemctl start vsftpd
systemctl enable vsftpd
firewall-cmd --permanent --add-service=ftp #在防火牆開啓時,啓用ftp服務(永久性)
firewall-cmd --reloadvim
效果:在網址中輸入ftp://172.25.254.122segmentfault
訪問數據端口:21
數據傳輸端口:>1024隨機端口
[root@localhost ~]# netstat -antlupe | grep vsftpd
tcp6 0 0 :::21 :::* LISTEN 0 47610 3199/vsftpd
默認發佈目錄:/var/ftp
訪問方式
lftp 172.25.254.122 ##匿名登錄 --> /var/ftp
lftp 172.25.254.122 -u student ##用戶登錄 --> /home/student
配置文件:安全
/etc/vsftpd/vsftpd.conf
[root@localhost ~]# rpm -qc vsftpd
/etc/logrotate.d/vsftpd
/etc/pam.d/vsftpd
/etc/vsftpd/ftpusers
/etc/vsftpd/user_list
/etc/vsftpd/vsftpd.confapp
anonymous_enable=YES|NO #匿名用戶是否能夠登錄
local_enable=YES|NO #本地用戶是否能夠登錄
write_enable=YES|NO #本地用戶十分可寫
每一次修改配置文件,都須要從新啓用
systemctl restart vsftpdtcp
默認本地用戶可寫:
ui
常見錯誤:
530 認證失敗
550 服務自己不支持
500 用戶權限過大
553 用戶權限太小
匿名用戶家目錄 /var/ftp/pub
chmod 775 /var/ftp/pub
chgrp ftp /var/ftp/pub
vim /etc/vsftpd/vsftpd.conf
29 anon_upload_enable=YES
systemctl restart vsftpd
172.25.254.122虛擬機:
[root@localhost ~]# ll -d /var/ftp/pub
drwxrwxr-x 2 root ftp 6 Aug 3 2015 /var/ftp/pub
172.25.254.22真機:
[kiosk@foundation22 Desktop]$ lftp 172.25.254.122
lftp 172.25.254.122:~> cd /pub
cd ok, cwd=/pub
lftp 172.25.254.122:/pub> ls
lftp 172.25.254.122:/pub> put /etc/passwd #匿名用戶可寫入文件
2323 bytes transferred
lftp 172.25.254.122:/pub> ls
-rw------- 1 14 50 2323 Aug 03 01:12 passwd
lftp 172.25.254.122:/pub> exit
添加
anon_world_readable_only=NO
lftp 172.25.254.122:/pub> ls
-rw------- 1 14 50 980 Aug 03 01:39 group
-rw------- 1 14 50 2323 Aug 03 01:12 passwd
lftp 172.25.254.122:/pub> get passwd
2323 bytes transferred
取消註釋
non_mkdir_write_enable=YES
lftp 172.25.254.122:/pub> mkdir test
mkdir ok, `test' created
lftp 172.25.254.122:/pub> ls
-rw------- 1 14 50 980 Aug 03 01:39 group
-rw------- 1 14 50 2323 Aug 03 01:12 passwd
drwx------ 2 14 50 6 Aug 03 01:41 test
添加
anon_other_write_enable=YES
lftp 172.25.254.122:/pub> ls
-rw------- 1 14 50 980 Aug 03 01:39 group
-rw------- 1 14 50 2323 Aug 03 01:12 passwd
drwx------ 2 14 50 6 Aug 03 01:41 test
lftp 172.25.254.122:/pub> mv passwd west
rename successful
lftp 172.25.254.122:/pub> rm -r test/
rm ok, `test/' removed
lftp 172.25.254.122:/pub> ls
-rw------- 1 14 50 980 Aug 03 01:39 group
-rw------- 1 14 50 2323 Aug 03 01:12 west
默認爲ftp
修改
chown_uploads=YES
chown_username=student
anon_max_rate=1024000 #以字節結束,1M
[root@foundation22 html]# dd if=/dev/zero of=/etc/star bs=1M count=10
10+0 records in
10+0 records out
10485760 bytes (10 MB) copied, 0.00550747 s, 1.9 GB/s
max_clients=1
anon_root=/sheen
虛擬機
[root@localhost ~]# mkdir /sheen
[root@localhost ~]# touch /sheen/file
[root@localhost ~]# vim /etc/vsftpd/vsftpd.conf
[root@localhost ~]# systemctl restart vsftpd
真機
[kiosk@foundation22 Desktop]$ lftp 172.25.254.122
lftp 172.25.254.122:~> ls
-rw-r--r-- 1 0 0 0 Aug 03 02:31 file
local_root=/directory
local_umask=xxx
chroot_local_user=YES
shell:chmod u-w /home/*
touch /etc/vsftpd/chroot_list
vim /etc/vsftpd/chroot_list
-->student
chroot_local_user=NO
chroot_list_enable=YES
chroot_list_file=/etc/vsftpd/chroot_list
chroot_local_user=YES
chroot_list_enable=YES
chroot_list_file=/etc/vsftpd/chroot_list
vim /etc/vsftpd/user_list #用戶臨時黑名單
vim /etc/vsftpd/ftpusers #永久黑名單
userlist_enable=YES
userlist_deny=NO
vim /etc/vsftpd/user_list #參數設定,此文件變成白名單,在此文件的用戶才能夠登錄
vim /etc/vsftpd/sheenfile #文件名稱任意
sheen1
123
star
123
db_load -T -t hash -f /etc/vsftpd/sheenfile /etc/vsftpd/sheenfile.db #加密
vim /etc/pam.d/sheen #認證文件,名稱任意
account required pam_userdb.so db=/etc/vsftpd/sheenfile
auth required pam_userdb.so db=/etc/vsftpd/sheenfile
vim /etc/vsftpd/vsftpd.conf
131 pam_service_name=sheen
userlist_enable=YES tcp_wrappers=YES guest_enable=YES #認證功能開啓 guest_username=ftp #以ftp身份登錄
真機
[kiosk@foundation22 Desktop]$ lftp 172.25.254.122 -u sheen1
Password:
lftp sheen1@172.25.254.122:~> ls
drwxrwxr-x 2 0 50 43 Aug 03 02:18 pub
lftp sheen1@172.25.254.122:/> exit
[kiosk@foundation22 Desktop]$ lftp 172.25.254.122 -u star
Password:
lftp star@172.25.254.122:~> ls
drwxrwxr-x 2 0 50 43 Aug 03 02:18 pub
lftp star@172.25.254.122:/> exit
vim /etc/vsftpd/vsftpd.conf
local_root=/ftphome/$USER
user_sub_token=$USER
mkdir /ftphome/sheen1/sheen1dir -p #這裏第二個目錄要和匿名用戶身份一致
mkdir /ftphome/star/stardir -p
echo $USER #SHELL裏輸出用戶
[kiosk@foundation22 Desktop]$ echo $USER
kiosk
真機
[kiosk@foundation22 Desktop]$ lftp 172.25.254.122 -u star
Password:
lftp star@172.25.254.122:~> ls
drwxr-xr-x 2 0 0 6 Aug 03 05:41 stardir
lftp star@172.25.254.122:/> exit
[kiosk@foundation22 Desktop]$ lftp 172.25.254.122 -u sheen1
Password:
lftp sheen1@172.25.254.122:~> ls
drwxr-xr-x 2 0 0 6 Aug 03 05:41 sheen1dir
chgrp ftp /ftphome/ -R chmod 775 /ftphome/sheen1/sheen1dir/ chmod 775 /ftphome/star/stardir/ vim /etc/vsftpd/vsftpd.conf 最後一行添加,把匿名用戶的權限註釋掉 user_config_dir=/etc/vsftpd/confdir mkdir /etc/vsftpd/confdir -p vim /etc/vsftpd/confdir/sheen1 #虛擬用戶的權限文件 anon_upload_enable=YES anon_world_readable_only=NO anon_mkdir_write_enable=YES anon_other_write_enable=YES systemctl restart vsftpd
真機: [kiosk@foundation22 Desktop]$ lftp 172.25.254.122 -u sheen1 Password: lftp sheen1@172.25.254.122:~> ls drwxrwxr-x 2 0 50 19 Aug 03 06:34 sheen1dir lftp sheen1@172.25.254.122:/> cd sheen1dir/ lftp sheen1@172.25.254.122:/sheen1dir> put /etc/passwd put: Access failed: 553 Could not create file. (passwd) lftp sheen1@172.25.254.122:/sheen1dir> put /etc/group 980 bytes transferred lftp sheen1@172.25.254.122:/sheen1dir> ls -rw------- 1 1000 50 980 Aug 03 06:43 group -rw------- 1 1000 50 2323 Aug 03 06:34 passwd lftp sheen1@172.25.254.122:/sheen1dir> rm -rf passwd rm ok, `passwd' removed lftp sheen1@172.25.254.122:/sheen1dir> put /etc/passwd 2323 bytes transferred lftp sheen1@172.25.254.122:/sheen1dir> ls -rw------- 1 1000 50 980 Aug 03 06:43 group -rw------- 1 1000 50 2323 Aug 03 06:43 passwd lftp sheen1@172.25.254.122:/sheen1dir> mv group w rename successful lftp sheen1@172.25.254.122:/sheen1dir> ls -rw------- 1 1000 50 2323 Aug 03 06:43 passwd -rw------- 1 1000 50 980 Aug 03 06:43 w lftp sheen1@172.25.254.122:/sheen1dir> exit [kiosk@foundation22 Desktop]$ lftp 172.25.254.122 -u star Password: lftp star@172.25.254.122:~> ls drwxrwxr-x 2 0 50 6 Aug 03 05:41 stardir lftp star@172.25.254.122:/> cd /stardir/ lftp star@172.25.254.122:/stardir> ls lftp star@172.25.254.122:/stardir> put /etc/passwd put: Access failed: 550 Permission denied. (passwd) lftp star@172.25.254.122:/stardir> ls lftp star@172.25.254.122:/stardir> exit