FTP服务器搭建与配置

FTP服务器搭建与配置html

  • FTP介绍
  • 使用vsftpd搭建ftp服务
  • xshell使用sftp传输文件
  • xshell使用xftp传输文件
  • 使用pure-ftpd搭建ftp服务

FTP介绍linux

FTP是File Transfer Protocol(文件传输协议,简称文件协议)的简称,用于在Internet上控制文件的双向传输。
FTP的主要做用就是让用户链接一个远程计算机(这些计算机上运行着FTP服务器程序)
并查看远程计算机中的文件,而后把文件从远程计算机复制到要地计算机,或是本地计算机的文件传送到远程计算机。
小公司用的多,大企业不用FTP,由于不安全。

使用vsftpd搭建ftp服务
安装vsftpd服务(192.168.221.10)shell

yum install vsftpd db4-utils -y  //db4-utils包用来生成密码库文件

创建与虚拟帐号相关联的系统帐号数据库

useradd -s /sbin/nologin virftp

创建与虚拟帐号相关的文件,更改权限,生成对应的库文件vim

vim /etc/vsftpd/vsftpd_login //奇数行为用户名,偶数行为密码
zhangsan
123456
lisi
654321
chmod 600 /etc/vsftpd/vsftpd_login
db_load -T -t hash -f /etc/vsftpd/vsftpd_login /etc/vsftpd/vsftpd_login.db

创建与虚拟帐号相关的目录以及配置文件(复制一份lisi的配置文件)安全

mkdir /etc/vsftpd/vsftpd_user_conf
cd /etc/vsftpd/vsftpd_user_conf
vim zhangsan //如下是文件内容
local_root=/home/virftp/zhangsan
anonymous_enable=NO
write_enable=YES
local_umask=022
anon_upload_enable=NO
idle_session_timeout=600
data_connection_timeout=120
max_clients=10
max_per_ip=5
local_max_rate=50000

建立虚拟用户的家目录和文件 服务器

mkdir /home/virftp/zhangsan
echo "zhangsan" > /home/virftp/zhangsan/zhangsan.txt

pam机制认证(让系统找到虚拟用户的密码文件)session

vim /etc/pam.d/vsftpd //添加以下两行
auth sufficient /lib64/security/pam_userdb.so db=/etc/vsftpd/vsftpd_login
account sufficient /lib64/security/pam_userdb.so db=/etc/vsftpd/vsftpd_login

修改virftp家目录下的目录与文件的全部者、组为virftpide

chown -R virftp:virftp /home/virftp/

修改主配置文件/etc/vsftpd/vsftpd.conf测试

vim /etc/vsftpd/vsftpd.conf  //如下是文件内容
anonymous_enable=NO
anon_upload_enable=NO
anon_mkdir_write_enable=NO

chroot_local_user=YES
guest_enable=YES
guest_username=virftp
virtual_use_local_privs=YES
user_config_dir=/etc/vsftpd/vsftpd_user_conf
allow_writeable_chroot=YES

启动vsftpd服务

systemctl start vsftpd

在vsftpd客户端上(192.168.221.20)安装lftp并访问ftp服务器(192.168.221.10)

yum install lftp.x86_64 -y
lftp zhangsan@192.168.221.20  //若是一直连不上,说明有防火墙

用户名或密码输错,就会报530
FTP服务器搭建与配置
测试

[root@apenglinux-002 ~]# lftp zhangsan@192.168.221.10
口令: 
lftp zhangsan@192.168.221.10:~> ls       
-rw-r--r--    1 1000     1000            9 Mar 04 12:32 zhangsan.txt

Xshell使用sftp传输文件
FTP服务器搭建与配置
FTP服务器搭建与配置
FTP服务器搭建与配置
FTP服务器搭建与配置

sftp:/root> help
bye     finish your SFTP session
cd      change your remote working directory
clear   clear screen
exit    finish your SFTP session
explore explore your local directory
get     download a file from the server to your local machine
help    give help
lcd     change and/or print local working directory
lls     list contents of a local directory
lpwd    print your local working directory
ls      list contents of a remote directory
mkdir   create a directory on the remote server
mv      move or rename a file on the remote server
put     upload a file from your local machine to the server
pwd     print your remote working directory
quit    finish your SFTP session
rename  move or rename a file on the remote server
rm      delete a file
rmdir   remove a directory on the remote server
sftp:/root> put   //会弹出一个窗口,可选择一个文件上传
Uploading vsftpd.txt to remote:/root/vsftpd.txt
sftp: sent 1.16 KB in 0.02 seconds

上传了一个vsftpd.txt文件到Linux中,发现中文乱码,则按以下解决

iconv -f gb2312 vsftpd.txt -o vs.txt //将编码为gb2312的文件vsftpd.txt转为linux可辨别的编码文件vs.txt

iconv命令

-f,--from-code=名称 原始文本编码
-t,--to-code=名称 输出编码
-o,--output=file 输出文件
-l,--list 列出全部已知的字符集

Xshell使用xftp传输文件

打开xshell链接到linux服务器之后,按ctrl+alt+f进入xftp的下载页面
安装xftp
xshell链接到Linux服务器之后, ctrl+alt+f就能够连上linux服务器
双击就可下载/上传文件了。
https://www.netsarang.com/news/ver6_beta_release.html

FTP服务器搭建与配置
使用pure-ftpd搭建ftp服务
安装pure-ftpd

yum install epel-release -y
yum install pure-ftpd -y

配置pure-ftpd

vim /etc/pure-ftpd/pure-ftpd.conf
# PureDB                        /etc/pure-ftpd/pureftpd.pdb  //去掉最前面的"#"
systemctl start pure-ftpd.service

创建系统帐号,虚拟帐号,虚拟帐号的根目录及测试文件

mkdir -p /pure-ftpd/zhangsan
echo "zhangsan" > /pure-ftpd/zhangsan/zhangsan.txt
useradd -s /sbin/nologin pure-ftp
pure-pw useradd zhangsan -u pure-ftp -d /pure-ftpd/zhangsan/  //输入密码两次

建立用户信息数据库文件

pure-pw mkdb

将虚拟用户的家目录和属主、组改成系统用户pure-ftp

chown -R pure-ftp:pure-ftp /pure-ftpd/zhangsan/

在同一机器上安装ftp客户端软件lftp

yum install lftp -y

访问ftp服务器

lftp zhangsan@127.0.0.1  //访问成功
口令: 
lftp zhangsan@127.0.0.1:~> ls       
drwxr-xr-x    2 1000       pure-ftp           26 Mar  5 07:58 .
drwxr-xr-x    2 1000       pure-ftp           26 Mar  5 07:58 ..
-rw-r--r--    1 1000       pure-ftp            9 Mar  5 07:58 zhangsan.txt

在另一台机器上安装lftp并访问ftp服务器(须要关闭服务器的防火墙)

yum install lftp -y
lftp zhangsan@192.168.221.20
口令: 
lftp zhangsan@192.168.221.20:~> ls       
drwxr-xr-x    2 1000       pure-ftp           26 Mar  5 07:58 .
drwxr-xr-x    2 1000       pure-ftp           26 Mar  5 07:58 ..
-rw-r--r--    1 1000       pure-ftp            9 Mar  5 07:58 zhangsan.txt
相关文章
相关标签/搜索