FTP服务
软件安装包: vsftpd
默认发布目录: /var/ftp
协议接口: 21/tcp
服务配置文件: /etc/vsftpd/vsftpd.conf
报错id的解析:
500 ##文件系统权限过大
530 ##用户认证失败
550 ##服务本身功能未开放
553 ##文件权过小
FTP(File Transfer Protocol),是文件传输协议的简称。用于Internet上的控制文件的双向传输。同时, 它也是一个应用程序(Application),用户可以通过它把自己的PC机与世界各地所有运行FTP协议的服务器相连, 访问服务器上的大量程序和信息。 FTP的主要功能是实现各种操作系统之间的文件交流,建立一个统一的文件传输协议。 ftp:// ##文件传输协议 vsftpd ##FTP服务器包
安装包
服务端: vsftd
客户端: lftp
服务端部署ftp服务
yum install -y vsftpd
systemctl start vsftpd
systemctl enable vsftpd
添加防火墙策略
##添加防火墙策略,让火墙允许ftp服务; --permanent表示永久添加
firewall-cmd --permanent --add-service=ftp
Success
##重新加载;必须执行,否则不生效
firewall-cmd --reload
success
firewall-cmd --list-all
关闭selinux
##查看selinux的状态
getenforce Enforcing
vim /etc/sysconfig/selinux
SELINUX=disabled
reboot
客户端部署
yum -y install lftp
连接命令:
lftp 172.25.254.234 -u chunyu
基本命令使用
##本地用户登陆 [kiosk@foundation34 ~]$ lftp 172.25.254.234 -u westos Password: lftp westos@172.25.254.234:~> ls -rw-r--r-- 1 0 0 0 Oct 31 15:18 westosfile1 -rw-r--r-- 1 0 0 0 Oct 31 15:18 westosfile2 -rw-r--r-- 1 0 0 0 Oct 31 15:18 westosfile3 ##上传文件 lftp westos@172.25.254.234:~> put /etc/passwd 3190 bytes transferred lftp westos@172.25.254.234:~> ls -rw-r--r-- 1 1001 1001 3190 Oct 31 15:19 passwd -rw-r--r-- 1 0 0 0 Oct 31 15:18 westosfile1 -rw-r--r-- 1 0 0 0 Oct 31 15:18 westosfile2 -rw-r--r-- 1 0 0 0 Oct 31 15:18 westosfile3 ##删除文件 lftp westos@172.25.254.234:~> rm passwd rm ok, `passwd' removed lftp westos@172.25.254.234:~> ls -rw-r--r-- 1 0 0 0 Oct 31 15:18 westosfile1 -rw-r--r-- 1 0 0 0 Oct 31 15:18 westosfile2 -rw-r--r-- 1 0 0 0 Oct 31 15:18 westosfile3 ##新建目录 lftp westos@172.25.254.234:~> mkdir hello mkdir ok, `hello' created lftp westos@172.25.254.234:~> ls drwxr-xr-x 2 1001 1001 6 Oct 31 15:20 hello -rw-r--r-- 1 0 0 0 Oct 31 15:18 westosfile1 -rw-r--r-- 1 0 0 0 Oct 31 15:18 westosfile2 -rw-r--r-- 1 0 0 0 Oct 31 15:18 westosfile3 ##但不能用使用touch命令 因为ftp服务界面并非支持所有shell中的所有命令 lftp westos@172.25.254.234:~> touch file Unknown command `touch'. lftp westos@172.25.254.234:~> exit
https://blog.csdn.net/lilygg/article/details/83616565
SFTP服务
sftp是Secure File Transfer Protocol的缩写,安全文件传送协议。可以为传输文件提供一种安全的网络的加密方法。SFTP 为 SSH的其中一部分,是一种传输档案至 Blogger 伺服器的安全方式。其实在SSH软件包中,已经包含了一个叫作SFTP(Secure File Transfer Protocol)的安全文件信息传输子系统,SFTP本身没有单独的守护进程,它必须使用sshd守护进程(端口号默认是22)来完成相应的连接和答复操作,所以从某种意义上来说,SFTP并不像一个服务器程序,而更像是一个客户端程序。SFTP同样是使用加密传输认证信息和传输的数据,所以,使用SFTP是非常安全的。但是,由于这种传输方式使用了加密/解密技术,所以传输效率比普通的FTP要低得多
本次使用系统自带的internal-sftp搭建sftp,因为需要用到chroot,所以openssh 版本不能低于4.8p1
ssh -V检查版本
创建用户
useradd chunyu
passwd chunyu
创建工作目录
mkdir /sftp/chunyu/
修改配置文件
vim /etc/ssh/sshd_config
在后边追加
Subsystem sftp internal-sftp Match Group sftp ChrootDirectory /sftp/%u ForceCommand internal-sftp AllowTcpForwarding no X11Forwarding no
参数说明:
Subsystem sftp internal-sftp:指定使用sftp服务使用系统自带的internal-sftp
Match Group sftp:用来匹配sftp组的用户,如果要匹配多个组,多个组之间用逗号分割。
注:当然也可以匹配用户,如:【Match User mysftp】,多个用户名
之间也是用逗号分割。
ChrootDirectory /sftp/%u:用chroot将用户的根目录指定到/sftp/%u,%u代表用户名,这
样用户就只能在/sftp/%u下活动。
ForceCommand internal-sftp:指定sftp命令
更改工作目录权限
chown root:sftp /sftp
chown root:sftp /sftp/tom
chmod 755 /sftp
chmod 755 /sftp/tom
权限说明:
目录的权限设定有两个要点:
1、由ChrootDirectory指定的目录开始一直往上到系统根目录为止的目录拥有者,都只能是 root,群组可以
是第一步创建的组,这里是sftp
2、由ChrootDirectory指定的目录开始一直往上到系统根目录为止,目录所属的群组都不可以 具有写的权限。
注:读(r,权限值为4)、写(w,权限值为2)、执行(x,权限值为1)。