安装FTP服务器


# mount /dev/cdrom /mnt/cdrom/

mount: /dev/sr0 is write-protected,mounting read-only

# cd /mnt/cdrom/Packages/

# ls ftp*

ftp-0.17-66.el7.x86_64.rpm

# rpm -Uvh ftp-0.17-66.el7.x86_64.rpm

warning: ftp-0.17-66.el7.x86_64.rpm: HeaderV3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY

Preparing...                         ################################# [100%]

Updating / installing...

  1:ftp-0.17-66.el7                 ################################# [100%]

 

# rpm -Uvh vsftpd-3.0.2-9.el7.x86_64.rpm

warning: vsftpd-3.0.2-9.el7.x86_64.rpm:Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY

Preparing...                         ################################# [100%]

Updating / installing...

  1:vsftpd-3.0.2-9.el7               ################################# [100%]

 

 

配置

 

 

# mkdir /ftp/open

做几个测试文件

# echo opentest > /ftp/open/open.txt

# echo filetest > /tmp/filetest1.txt

 

# touch /ftp/open/anontest.txt

 

# rpm -qc vsftpd

/etc/logrotate.d/vsftpd

/etc/pam.d/vsftpd

/etc/vsftpd/ftpusers

/etc/vsftpd/user_list

/etc/vsftpd/vsftpd.conf

 

# cd /etc/vsftpd/

# cp vsftpd.conf vsftpd.conf.origin

 

创建密码明文文件

# vi /etc/vsftpd/vftpuser.txt

alice

P@ssw0rd

jack

P@ssw0rd

tom

P@ssw0rd

 

根据明文创建密码DB文件

# db_load -T -t hash -f /etc/vsftpd/vftpuser.txt\

/etc/vsftpd/vftpuser.db

 

查看密码数据文件

# file /etc/vsftpd/vftpuser.db

/etc/vsftpd/vftpuser.db: Berkeley DB (Hash,version 9, native byte-order)

 

创建vftpdguest账户

# useradd -d /ftp/private -s /sbin/nologinvftpuser

 

# vi /etc/pam.d/vsftpd

authaccount的所有配置行行均注释掉,添加如下内容:

auth required pam_userdb.sodb=/etc/vsftpd/vftpuser

account required pam_userdb.sodb=/etc/vsftpd/vftpuser

 

# vi /etc/vsftpd/vsftpd.conf

在最后添加

anon_root=/ftp/open

virtual_use_local_privs=YES

guest_enable=YES

guest_username=vftpuser

chroot_local_user=YES

allow_writeable_chroot=YES

 

# systemctl enable vsftpd

ln -s'/usr/lib/systemd/system/vsftpd.service''/etc/systemd/system/multi-user.target.wants/vsftpd.service'

 

# systemctl start vsftpd

 

测试

 

 

# ftp localhost

Trying ::1...

Connected to localhost (::1).

220 (vsFTPd 3.0.2)

Name (localhost:root): anonymous

331 Please specify the password.

Password:

230 Login successful.

Remote system type is UNIX.

Using binary mode to transfer files.

ftp> pwd

257 "/"

ftp> !pwd

/etc/vsftpd

ftp> ls

229 Entering Extended Passive Mode(|||51702|).

150 Here comes the directory listing.

-rw-r--r--    1 0       0               0 Aug 17 06:27anontest.txt

-rw-r--r--    1 0       0               9 Aug 17 06:27filetest1.txt

-rw-r--r--    1 0       0               9 Aug 17 06:27 open.txt

226 Directory send OK.

ftp> lcd /tmp

Local directory now /tmp

ftp> get open.txt

local: open.txt remote: open.txt

229 Entering Extended Passive Mode(|||44251|).

150 Opening BINARY mode data connection foropen.txt (9 bytes).

226 Transfer complete.

9 bytes received in 7.7e-05 secs (116.88Kbytes/sec)

ftp> quit

221 Goodbye.

 

 

# ftp localhost

Trying ::1...

Connected to localhost (::1).

220 (vsFTPd 3.0.2)

Name (localhost:root): alice

331 Please specify the password.

Password:

230 Login successful.

Remote system type is UNIX.

Using binary mode to transfer files.

ftp> ls

229 Entering Extended Passive Mode(|||21750|).

150 Here comes the directory listing.

226 Directory send OK.

ftp> !ls /tmp

filetest1.txt     open.txt   systemd-private-9xPN7y vmware-fonts0     vmware-installer1 vmware-root            vmware-tools-distrib

ks-script-_Yi85R  SAMBA.docx vmware-config0         vmware-installer0 vmware-installer2 vmware-root-2117481760  yum.log

ftp> lcd /tmp

Local directory now /tmp

ftp> put filetest1.txt

local: filetest1.txt remote: filetest1.txt

229 Entering Extended Passive Mode(|||65399|).

150 Ok to send data.

226 Transfer complete.

9 bytes sent in 5.9e-05 secs (152.54Kbytes/sec)

ftp> bye

221 Goodbye.