本文共 4518 字,大约阅读时间需要 15 分钟。
FTP服务器搭建与配置
FTP介绍
FTP是File Transfer Protocol(文件传输协议,简称文件协议)的简称,用于在Internet上控制文件的双向传输。FTP的主要作用就是让用户连接一个远程计算机(这些计算机上运行着FTP服务器程序)并查看远程计算机中的文件,然后把文件从远程计算机复制到要地计算机,或是本地计算机的文件传送到远程计算机。小公司用的多,大企业不用FTP,因为不安全。
使用vsftpd搭建ftp服务
安装vsftpd服务(192.168.221.10)yum install vsftpd db4-utils -y //db4-utils包用来生成密码库文件
建立与虚拟账号相关联的系统账号
useradd -s /sbin/nologin virftp
建立与虚拟账号相关的文件,更改权限,生成对应的库文件
vim /etc/vsftpd/vsftpd_login //奇数行为用户名,偶数行为密码zhangsan123456lisi654321chmod 600 /etc/vsftpd/vsftpd_logindb_load -T -t hash -f /etc/vsftpd/vsftpd_login /etc/vsftpd/vsftpd_login.db
建立与虚拟账号相关的目录以及配置文件(复制一份lisi的配置文件)
mkdir /etc/vsftpd/vsftpd_user_confcd /etc/vsftpd/vsftpd_user_confvim zhangsan //以下是文件内容local_root=/home/virftp/zhangsananonymous_enable=NOwrite_enable=YESlocal_umask=022anon_upload_enable=NOidle_session_timeout=600data_connection_timeout=120max_clients=10max_per_ip=5local_max_rate=50000
创建虚拟用户的家目录和文件
mkdir /home/virftp/zhangsanecho "zhangsan" > /home/virftp/zhangsan/zhangsan.txt
pam机制认证(让系统找到虚拟用户的密码文件)
vim /etc/pam.d/vsftpd //添加如下两行auth sufficient /lib64/security/pam_userdb.so db=/etc/vsftpd/vsftpd_loginaccount sufficient /lib64/security/pam_userdb.so db=/etc/vsftpd/vsftpd_login
修改virftp家目录下的目录与文件的所有者、组为virftp
chown -R virftp:virftp /home/virftp/
修改主配置文件/etc/vsftpd/vsftpd.conf
vim /etc/vsftpd/vsftpd.conf //以下是文件内容anonymous_enable=NOanon_upload_enable=NOanon_mkdir_write_enable=NOchroot_local_user=YESguest_enable=YESguest_username=virftpvirtual_use_local_privs=YESuser_config_dir=/etc/vsftpd/vsftpd_user_confallow_writeable_chroot=YES
启动vsftpd服务
systemctl start vsftpd
在vsftpd客户端上(192.168.221.20)安装lftp并访问ftp服务器(192.168.221.10)
yum install lftp.x86_64 -ylftp zhangsan@192.168.221.20 //如果一直连不上,说明有防火墙
用户名或密码输错,就会报530
[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传输文件
sftp:/root> helpbye finish your SFTP sessioncd change your remote working directoryclear clear screenexit finish your SFTP sessionexplore explore your local directoryget download a file from the server to your local machinehelp give helplcd change and/or print local working directorylls list contents of a local directorylpwd print your local working directoryls list contents of a remote directorymkdir create a directory on the remote servermv move or rename a file on the remote serverput upload a file from your local machine to the serverpwd print your remote working directoryquit finish your SFTP sessionrename move or rename a file on the remote serverrm delete a filermdir remove a directory on the remote server
sftp:/root> put //会弹出一个窗口,可选择一个文件上传Uploading vsftpd.txt to remote:/root/vsftpd.txtsftp: 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的下载页面安装xftpxshell连接到Linux服务器以后, ctrl+alt+f就可以连上linux服务器双击就可下载/上传文件了。
https://www.netsarang.com/news/ver6_beta_release.html
yum install epel-release -yyum 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/zhangsanecho "zhangsan" > /pure-ftpd/zhangsan/zhangsan.txtuseradd -s /sbin/nologin pure-ftppure-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 -ylftp 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
转载于:https://blog.51cto.com/13480443/2082853