且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

15.4 xshell使用xftp传输文件 15.5 使用pure-ftpd搭建ftp服务

更新时间:2022-10-03 14:18:49

15.4 xshell使用xftp传输文件

  • 打开xshell,新建一个会话窗口

  • 15.4 xshell使用xftp传输文件 15.5 使用pure-ftpd搭建ftp服务

  • 15.4 xshell使用xftp传输文件 15.5 使用pure-ftpd搭建ftp服务

  • 输入它的用户名 root 密码123465

  • 15.4 xshell使用xftp传输文件 15.5 使用pure-ftpd搭建ftp服务

  • 这个时候它默认是在root下

sftp:/root> ls
dr-xr-x---    5 root     root          259 Nov  2 22:00 .
dr-xr-xr-x   18 root     root          236 Oct  5 15:52 ..
-rw-r--r--    1 root     root           18 Dec 29  2013 .bash_logout
-rw-------    1 root     root         6472 Oct 30 23:09 .mysql_history
-rw-r--r--    1 root     root          176 Dec 29  2013 .bash_profile
-rw-r--r--    1 root     root          176 Dec 29  2013 .bashrc
-rw-r--r--    1 root     root          100 Dec 29  2013 .cshrc
-rw-r--r--    1 root     root          129 Dec 29  2013 .tcshrc
-rw-------    1 root     root         1261 Oct  5 22:26 anaconda-ks.cfg
-rw-------    1 root     root        27894 Nov  1 22:35 .bash_history
drwxr-----    3 root     root           19 Oct  5 21:56 .pki
-rw-------    1 root     root         1024 Oct 23 22:25 .rnd
-rw-------    1 root     root           91 Oct 30 23:19 .lesshst
-rw-------    1 root     root         7537 Nov  2 21:45 .viminfo
drwxr-xr-x    3 root     root           19 Nov  2 21:57 .local
drwxr-xr-x    3 root     root           18 Nov  2 21:57 .config
-rw-r--r--    1 root     root            0 Nov  2 21:25 aming.txt
sftp:/root> 

sftp:/root> cd /tmp
sftp:/tmp> ls
drwxrwxrwt    8 root     root          240 Nov  2 21:55 .
dr-xr-xr-x   18 root     root          236 Oct  5 15:52 ..
srwxrwxrwx    1 mysql    mysql           0 Nov  2 20:45 mysql.sock
srw-rw-rw-    1 root     root            0 Nov  2 20:45 php-fcgi.sock
srw-rw-rw-    1 root     root            0 Nov  2 20:45 aming.sock
-rw-r--r--    1 root     root            0 Nov  2 20:45 test.com.log
drwx------    3 root     root           60 Nov  2 20:45 systemd-private-5e78e1c53e0f46fcab6cfa62e93122d0-vmtoolsd.service-hMpOXS
drwxrwxrwt    2 root     root           40 Nov  2 20:45 .XIM-unix
drwxrwxrwt    2 root     root           40 Nov  2 20:45 .ICE-unix
drwxrwxrwt    2 root     root           40 Nov  2 20:45 .font-unix
drwxrwxrwt    2 root     root           40 Nov  2 20:45 .Test-unix
drwxrwxrwt    2 root     root           40 Nov  2 20:45 .X11-unix
  • 可以get一个文件

Fetching /tmp/test.com.log to test.com.logsftp: received 0 in 0.02 seconds
sftp:/tmp>
  • get的文件在这里

  • 15.4 xshell使用xftp传输文件 15.5 使用pure-ftpd搭建ftp服务

  • 默认是放到桌面上15.4 xshell使用xftp传输文件 15.5 使用pure-ftpd搭建ftp服务

  • 这个时候get一个文件,它直接回给你传到你的桌面上

  • 15.4 xshell使用xftp传输文件 15.5 使用pure-ftpd搭建ftp服务

  • 这种是命令行,不太直观,

  • 实际上还有一种方案,使用xftp,这个需要你安装一个插件的,可以使用快捷键ctrl alt f

  • 15.4 xshell使用xftp传输文件 15.5 使用pure-ftpd搭建ftp服务

  • 使用xshell登录一个在线的主机,按下ctrl+alt+f,会自动弹出一个xftp的提示下载界面

  • 直接点击下载ftp,这里直接去r.aminglinux.com 找下载好的文件

  • 15.4 xshell使用xftp传输文件 15.5 使用pure-ftpd搭建ftp服务

  • 15.4 xshell使用xftp传输文件 15.5 使用pure-ftpd搭建ftp服务

  • 15.4 xshell使用xftp传输文件 15.5 使用pure-ftpd搭建ftp服务

  • 15.4 xshell使用xftp传输文件 15.5 使用pure-ftpd搭建ftp服务

  • 先把这个关掉,再去服务端机器上 再来运行Ctrl alt f

  • 15.4 xshell使用xftp传输文件 15.5 使用pure-ftpd搭建ftp服务

  • 15.4 xshell使用xftp传输文件 15.5 使用pure-ftpd搭建ftp服务

  • 现在把21端口的 vsftpd 服务停掉,再试下传输文件

[root@aming-01 ~]# systemctl stop vsftpd
[root@aming-01 ~]# netstat -lntpActive Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
tcp        0      0 0.0.0.0:111             0.0.0.0:*               LISTEN      1/systemd           
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      1239/nginx: master  
tcp        0      0 0.0.0.0:20048           0.0.0.0:*               LISTEN      1067/rpc.mountd     
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      1002/sshd           
tcp        0      0 0.0.0.0:43927           0.0.0.0:*               LISTEN      -                   
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      2134/master         
tcp        0      0 0.0.0.0:443             0.0.0.0:*               LISTEN      1239/nginx: master  
tcp        0      0 0.0.0.0:2049            0.0.0.0:*               LISTEN      -                   
tcp        0      0 0.0.0.0:38024           0.0.0.0:*               LISTEN      910/rpc.statd       
tcp6       0      0 :::3306                 :::*                    LISTEN      2026/mysqld         
tcp6       0      0 :::111                  :::*                    LISTEN      1/systemd           
tcp6       0      0 :::20048                :::*                    LISTEN      1067/rpc.mountd     
tcp6       0      0 :::34868                :::*                    LISTEN      910/rpc.statd       
tcp6       0      0 :::22                   :::*                    LISTEN      1002/sshd           
tcp6       0      0 ::1:25                  :::*                    LISTEN      2134/master         
tcp6       0      0 :::41152                :::*                    LISTEN      -                   
tcp6       0      0 :::2049                 :::*                    LISTEN      -                   
[root@aming-01 ~]#

-双击文件或者把文件拖过去就可以 15.4 xshell使用xftp传输文件 15.5 使用pure-ftpd搭建ftp服务

  • 现在桌面已经有这个文件了aming.txt 15.4 xshell使用xftp传输文件 15.5 使用pure-ftpd搭建ftp服务


  • 1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
    335
    336
    337
    338
    339
    340
    341
    342
    343
    # 15.5 使用pure-ftpd搭建ftp服务
    - pure-ftpd 比vftpd更加的轻量;更加简单
    - 安装包
    - yum install -y pure-ftpd
    ```
    [root@aming-01 ~]# yum install -y pure-ftpd
    已加载插件:fastestmirror
    Loading mirror speeds from cached hostfile
     
    已安装:
      pure-ftpd.x86_64 0:1.0.42-3.el7                                                            
     
    作为依赖被安装:
      postgresql-libs.x86_64 0:9.2.23-1.el7_4            usermode.x86_64 0:1.111-5.el7           
     
    完毕!
    [root@aming-01 ~]
    ```
    - 更改配置文件vim /etc/pure-ftpd/pure-ftpd.conf
    ```
    [root@aming-01 ~]# vim /etc/pure-ftpd/pure-ftpd.conf
     
     
    ############################################################
    #                                                          #
    #         Configuration file for pure-ftpd wrappers        #
    #                                                          #
    ############################################################
     
    # If you want to run Pure-FTPd with this configuration   
    # instead of command-line options, please run the
    # following command :
    #
    # /usr/sbin/pure-config.pl /etc/pure-ftpd/pure-ftpd.conf
    #
    # Please don't forget to have a look at documentation at
    # http://www.pureftpd.org/documentation.shtml for a complete list of
    # options.
     
    # Cage in every user in his home directory
     
    ChrootEveryone              yes
     
     
     
    # If the previous option is set to "no", members of the following group
    # won't be caged. Others will be. If you don't want chroot()ing anyone,
    # just comment out ChrootEveryone and TrustedGID.
     
    # TrustedGID                    100
    ```
    - 搜索pdb  把前面的井号删除,y也就是说要把前面的密码 这一行指定
    ```
    PureDB                        /etc/pure-ftpd/pureftpd.pdb
     
     
    # Path to pure-authd socket (see README.Authentication-Modules)
     
    # ExtAuth                       /var/run/ftpd.sock
     
     
     
    # If you want to enable PAM authentication, uncomment the following line
     
    PAMAuthentication             yes
     
     
     
    :wq   
    [root@aming-01 ~]# vim /etc/pure-ftpd/pure-ftpd.conf
    [root@aming-01 ~]
    ```
    - 因为vsftpd 和pure-ftpd 都是监听21端口,如果装有vsftpd,需要先暂停服务,如果不停掉在启动pure-ftpd的时候会报错,因为你的21端口被占用了,
    ```
    [root@aming-01 ~]# systemctl stop vsftpd
    [root@aming-01 ~]# systemctl start pure-ftpd
    [root@aming-01 ~]# ps aux |grep ftp
    root       2396  0.0  0.1  53188  1944 ?        Ss   23:24   0:00 /usr/libexec/openssh/sftp-server
    root       2535  0.0  0.1 202424  1196 ?        Ss   23:49   0:00 pure-ftpd (SERVER)
    root       2537  0.0  0.0 112680   980 pts/0    R+   23:50   0:00 grep --color=auto ftp
    [root@aming-01 ~]# netstat -lntp
    Active Internet connections (only servers)
    Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
    tcp        0      0 0.0.0.0:111             0.0.0.0:*               LISTEN      1/systemd           
    tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      1239/nginx: master  
    tcp        0      0 0.0.0.0:20048           0.0.0.0:*               LISTEN      1067/rpc.mountd     
    tcp        0      0 0.0.0.0:21              0.0.0.0:*               LISTEN      2535/pure-ftpd (SER 
    tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      1002/sshd           
    tcp        0      0 0.0.0.0:43927           0.0.0.0:*               LISTEN      -                   
    tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      2134/master         
    tcp        0      0 0.0.0.0:443             0.0.0.0:*               LISTEN      1239/nginx: master  
    tcp        0      0 0.0.0.0:2049            0.0.0.0:*               LISTEN      -                   
    tcp        0      0 0.0.0.0:38024           0.0.0.0:*               LISTEN      910/rpc.statd       
    tcp6       0      0 :::3306                 :::*                    LISTEN      2026/mysqld         
    tcp6       0      0 :::111                  :::*                    LISTEN      1/systemd           
    tcp6       0      0 :::20048                :::*                    LISTEN      1067/rpc.mountd     
    tcp6       0      0 :::34868                :::*                    LISTEN      910/rpc.statd       
    tcp6       0      0 :::21                   :::*                    LISTEN      2535/pure-ftpd (SER 
    tcp6       0      0 :::22                   :::*                    LISTEN      1002/sshd           
    tcp6       0      0 ::1:25                  :::*                    LISTEN      2134/master         
    tcp6       0      0 :::41152                :::*                    LISTEN      -                   
    tcp6       0      0 :::2049                 :::*                    LISTEN      -                   
    [root@aming-01 ~]
     
    ```
    - 下面我们来创建一个测试的目录
    - 给pure-ftpd用户使用
    mkdir /data/ftp
    - 创建一个普通用户
    useradd -u 1010 pure-ftp
    - 更改一下属主、属组权限
    chown -R pure-ftp:pure-ftp /data/ftp
    - 创建一个用户,
    - 同样是虚拟用户映射系统用户
    pure-pw useradd [指定用户] -u [指定系统用户]  -d [指定虚拟用户的家目录]
    pure-pw useradd ftp_usera -u pure-ftp  -d /data/ftp    //密码为“123456”
    - 添加完之后,让 pure-ftpd 建立虚拟用户数据 pure-pw mkdb 
     
    - 查看命令说明文件pure-pw list/userdel/usermod/passwd
    ```
    [root@aming-01 ~]# mkdir /data/ftp
    [root@aming-01 ~]# useradd -u 1010 pure-ftp
    [root@aming-01 ~]# chown -R pure-ftp:pure-ftp /data/ftp
    [root@aming-01 ~]
     
     
    [root@aming-01 ~]# pure-pw useradd ftp_usera -u pure-ftp  -d /data/ftp
    Password: 
    Enter it again: 
    [root@aming-01 ~]# pure-pw mkdb
     
    ```
    - 下面来测试下
    ```
    [root@aming-01 ~]# touch /data/ftp/123.txt
    [root@aming-01 ~]# lftp ftp_usera@127.0.0.1
    口令: 
    lftp ftp_usera@127.0.0.1:~> ls      
    drwxr-xr-x    2 1010       pure-ftp           21 Nov  3 00:00 .
    drwxr-xr-x    2 1010       pure-ftp           21 Nov  3 00:00 ..
    -rw-r--r--    1 0          0                   0 Nov  3 00:00 123.txt
    lftp ftp_usera@127.0.0.1:/> 
    ```
    - 不妨给它改下属主属组
    ```
    lftp ftp_usera@127.0.0.1:/> quit
    [root@aming-01 ~]# chown pure-ftp:pure-ftp /data/ftp/123.txt
    [root@aming-01 ~]# lftp ftp_usera@127.0.0.1
    口令: 
    lftp ftp_usera@127.0.0.1:~> ls      
    drwxr-xr-x    2 1010       pure-ftp           21 Nov  3 00:00 .
    drwxr-xr-x    2 1010       pure-ftp           21 Nov  3 00:00 ..
    -rw-r--r--    1 1010       pure-ftp            0 Nov  3 00:00 123.txt
    lftp ftp_usera@127.0.0.1:/> 
    lftp ftp_usera@127.0.0.1:/> quit
    [root@aming-01 ~]
     
    ```
     
     
    - 扩展
    - [x] vsftp使用mysql存放虚拟用户并验证 http://www.aminglinux.com/bbs/thread-342-1-1.html
     
    vsftp 利用mysql 验证虚拟账户
     
    账户 验证 虚拟 vsftp mysql 资料分享
    1  安装vsftpd
    ```
    (1) yum install -y  vsftpd
     
    (2)编辑vsftpd.conf
     
    内容如下
     
    listen=YES
     
    connect_from_port_20=YES
     
    pasv_enable=YES
     
    tcp_wrappers=YES
     
    local_enable=YES
     
    chroot_local_user=yes
     
    anonymous_enable=NO
     
    guest_enable=YES
     
    guest_username=vsftpdguest
     
    user_config_dir=/etc/vsftpd/vsftpd_user_conf
     
    pam_service_name=/etc/pam.d/vsftpd
     
    dirmessage_enable=YES
     
    idle_session_timeout=600
     
    check_shell=NO
     
    (3)创建一个虚拟用户映射系统用户    
     
    useradd –s /sbin/nologin vsftpdguest
     
    2 安装 mysql
     
    具体步骤参考 http://www.lishiming.net/thread-7-1-2.html
     
    3 安装 pam-mysql
     
    wget  https://nchc.dl.sourceforge.net/project/pam-mysql/pam-mysql/0.7RC1/pam_mysql-0.7RC1.tar.gz
     
    tar zxvf  pam_mysql-0.7RC1.tar.gz
     
    cd pam_mysql-0.7RC1
     
    ./configure --with-mysql=/usr/local/mysql --with-pam=/usr --with-pam-mods-dir=/usr/lib
     
    make && make install
     
    4 创建vsftp 库和相关的表并授权
     
    >create database vsftp;
     
    >use vsftp ;
     
    >create table users ( name char(16) binary ,passwd char(125) binary ) ;
     
    >insert into users (name,passwd) values ('test001',password('123456'));
     
    >insert into users (name,passwd) values ('test002',password('234567'));
     
    >grant select on vsftp.users to vsftpdguest@localhost identified by 'vsftpdguest';
    ```
    5 创建虚拟账户的配置文件
    ```
     
    mkdir /etc/vsftpd/vsftpd_user_conf 
     
    cd  /etc/vsftpd/vsftpd_user_conf
     
    vim test001
     
    内容如下
     
    local_root=/ftp/        
     
    write_enable=YES
     
    virtual_use_local_privs=YES
     
    chmod_enable=YES
     
    6  编辑验证文件
     
    vim  /etc/pam.d/vsftpd
     
    内容如下
     
    #%PAM-1.0
     
    auth required /usr/lib/pam_mysql.so user=vsftpdguest passwd=vsftpdguest host=localhost db=vsftp table=users usercolumn=name passwdcolumn=passwd crypt=2
     
    account required /usr/lib/pam_mysql.so user=vsftpdguest passwd=vsftpdguest host=localhost db=vsftp table=users usercolumn=name passwdcolumn=passwd crypt=2
    ```
    - 如果不想使用mysql也可以使用文件的形式来搞虚拟账号,请参考  Centos5.5 配置vsftpd 虚拟账号
     
     
     
     
     
     
     
     
     
     
     
    - [x]  ftp的主动和被动模式 http://www.aminglinux.com/bbs/thread-961-1-1.html
    ftp的主动模式与被动模式的区别是什么?
     
     
    中文意思 客户端 服务器 资料分享
    FTP协议有两种工作方式:PORT方式和PASV方式,中文意思为主动模式和被动模式
    一、什么是主动FTP  
     
            主动模式的FTP工作原理:客户端从一个任意的非特权端口N连接到FTP服务器的命令端口,也就是21端口。然后客户端开始监听端口N+1,并发送FTP命令“port N+1”到FTP服务器。接着服务器会从它自己的数据端口(20)连接到客户端指定的数据端口(N+1)。
     
        针对FTP服务器前面的防火墙来说,必须允许以下通讯才能支持主动方式FTP:    
     
        1、 任何大于1024的端口到FTP服务器的21端口。(客户端初始化的连接)  
     
        2、 FTP服务器的21端口到大于1024的端口。 (服务器响应客户端的控制端口) 
     
        3、 FTP服务器的20端口到大于1024的端口。(服务器端初始化数据连接到客户端的数据端口)
     
        4、 大于1024端口到FTP服务器的20端口(客户端发送ACK响应到服务器的数据端口) 
     
    二、什么是被动FTP  
     
        为了解决服务器发起到客户的连接的问题,人们开发了一种不同的FTP连接方式。这就是所谓的被动方式,或者叫做PASV,当客户端通知服务器它处于被动模式时才启用。
     
       在被动方式FTP中,命令连接和数据连接都由客户端发起,这样就可以解决从服务器到客户端的数据端口的入方向连接被防火墙过滤掉的问题。
     
       当开启一个 FTP连接时,客户端打开两个任意的非特权本地端口(N > 1024和N+1)。第一个端口连接服务器的21端口,但与主动方式的FTP不同,客户端不会提交PORT命令并允许服务器来回连它的数据端口,而是提交 PASV命令。这样做的结果是服务器会开启一个任意的非特权端口(P > 1024),并发送PORT P命令给客户端。然后客户端发起从本地端口N+1到服务器的端口P的连接用来传送数据。  
     
           对于服务器端的防火墙来说,必须允许下面的通讯才能支持被动方式的FTP:     
     
        1、 从任何大于1024的端口到服务器的21端口(客户端初始化的连接)  
     
        2、 服务器的21端口到任何大于1024的端口(服务器响应到客户端的控制端口的连接) 
     
        3、 从任何大于1024端口到服务器的大于1024端口(客户端初始化数据连接到服务器指定的任意端口)
     
        4、 服务器的大于1024端口到远程的大于1024的端口(服务器发送ACK响应和数据到客户端的数据端口)
     
    从上面可以看出,两种方式的命令链路连接方法是一样的,而数据链路的建立方法就完全不同,如下图:
    FTP服务器的主动工作模式
    port.jpg
     
    FTP服务器的被动工作模式
    pasv.jpg
     
     
    以上关于主动和被动FTP的解释,可以简单概括为以下两点:
     
        1、主动FTP:  
     
                命令连接:客户端 >1024端口 -> 服务器 21端口  
     
                数据连接:客户端 >1024端口 <- 服务器 20端口 
     
        2、被动FTP: 
     
                命令连接:客户端 >1024端口 -> 服务器 21端口 
     
                数据连接:客户端 >1024端口 -> 服务器 >1024端口
     
    三、主动模式ftp与被动模式FTP优点和缺点:       
     
       主动FTP对FTP服务器的管理和安全很有利,但对客户端的管理不利。因为FTP服务器企图与客户端的高位随机端口建立连接,而这个端口很有可能被客户端的防火墙阻塞掉。被动FTP对FTP客户端的管理有利,但对服务器端的管理不利。因为客户端要与服务器端建立两个连接,其中一个连到一个高位随机端口,而这个端口很有可能被服务器端的防火墙阻塞掉。
    pasv.jpg    
    本文转自   ch71smas    51CTO博客,原文链接:http://blog.51cto.com/ch71smas/1977609