设为首页 收藏本站
查看: 1900|回复: 0

[经验分享] vsftpd的安装配置及lftp命令的使用

[复制链接]
累计签到:1 天
连续签到:1 天
发表于 2016-1-25 10:18:00 | 显示全部楼层 |阅读模式
vsftpd(very secure FTP daemon)是一个基于GPL发布的类Unix系统上使用的FTP服务器软件,它是一个安全、高速、稳定的FTP服务器
一、FTP
  FTP(File Transfer Protocol,文件传输协议)用于Internet上的控制文件的双向传输。同时,它也是一个应用程序(Application)。基于不同的操作系统有不同的FTP应用程序,而所有这些应用程序都遵守同一种协议以传输文件。
  1、ftp基于C/S架构
       client:
           ftp、lftp、lftpget、wget、curl、filezilla、gftp(Linux GUI)、flashfxp、cuteftp
       server:监听在21/tcp           
           wu-ftpd、proftpd、pureftp、vsftpd、ServU
  2、FTP客户端与服务器的连接:
       命令连接:文件管理类命令,始终在线的连接
       数据连接:数据传输,按需创建及关闭的连接

       client与server的连接模式有两种:
         ①Standard(PORT方式,主动方式)
           FTP 客户端首先和服务器的TCP 21端口建立连接,用来发送命令,客户端需要接收数据的时候在这个通道上发送PORT命令。PORT命令包含了客户端用什么端口接收数据。在传送数据的时候,服务器端通过自己的TCP 20端口连接至客户端的指定端口发送数据
           例如:         
              命令:Client: 50000 --> Server: 21
              数据:Server: 20/tcp --> Client: 50000+1
         ②Passive(PASV,被动方式)
            建立控制通道和Standard模式类似,但建立连接后发送Pasv命令。服务器收到Pasv命令后,打开一个临时端口(端口号大于1023小于65535)并且通知客户端在这个端口上传送数据的请求,客户端连接FTP服务器此端口,然后FTP服务器将通过这个端口传送数据
           例如:            
              命令:Client: 50000 --> Server: 21
              数据:Client: 50000+1 --> Server: 随机端口
  3、响应码:
         1xx: 信息
         2xx: 成功类的状态码
         3xx: 提示需进一步提供补充类信息的状态码
         4xx: 客户端错误
         5xx: 服务端错误

二、vsftpd的安装配置
     安装:yum -y install vsftpd
     主配置文件:/etc/vsftpd/vsftpd.conf
     用户认证配置文件:/etc/pam.d/vsftpd
     服务脚本:/etc/rc.d/init.d/vsftpd
     vsftpd允许客户端以匿名、本地或虚拟用户的身份访问:
        匿名用户(映射为ftp用户)共享资源位置:/var/ftp
        本地用户通过ftp访问的资源位置:用户自己的家目录
        虚拟用户通过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
[iyunv@node2 ~]# yum -y install vsftpd
...
[iyunv@node2 ~]# rpm -ql vsftpd
/etc/logrotate.d/vsftpd    #实现日志滚动功能的脚本
/etc/pam.d/vsftpd
/etc/rc.d/init.d/vsftpd
/etc/vsftpd
/etc/vsftpd/ftpusers
/etc/vsftpd/user_list
/etc/vsftpd/vsftpd.conf   #主配置文件
/etc/vsftpd/vsftpd_conf_migrate.sh
/usr/sbin/vsftpd    #主程序
...
/var/ftp    #匿名用户共享资源目录
/var/ftp/pub
[iyunv@node2 ~]# service vsftpd start
Starting vsftpd for vsftpd:                                [  OK  ]
[iyunv@node2 ~]# netstat -tnap
...
tcp        0      0 0.0.0.0:21                  0.0.0.0:*                   LISTEN      34001/vsftpd
...
[iyunv@node2 ~]# yum -y install ftp
...
[iyunv@node2 ~]# ftp 192.168.30.20
Connected to 192.168.30.20 (192.168.30.20).
220 (vsFTPd 2.2.2)
Name (192.168.30.20:root): ftp
331 Please specify the password.
Password:
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> help
Commands may be abbreviated.  Commands are:

!       debug       mdir        sendport    site
$       dir     mget        put     size
account     disconnect  mkdir       pwd     status
append      exit        mls     quit        struct
ascii       form        mode        quote       system
bell        get     modtime     recv        sunique
binary      glob        mput        reget       tenex
bye     hash        newer       rstatus     tick
case        help        nmap        rhelp       trace
cd      idle        nlist       rename      type
cdup        image       ntrans      reset       user
chmod       lcd     open        restart     umask
close       ls      prompt      rmdir       verbose
cr      macdef      passive     runique     ?
delete      mdelete     proxy       send
ftp> ls
227 Entering Passive Mode (192,168,30,20,234,38).
150 Here comes the directory listing.
drwxr-xr-x    2 0        0            4096 Jul 24 00:49 pub
226 Directory send OK.
ftp> bye
421 Timeout.




   1、匿名用户的配置:
        anonymous_enable=YES
        anon_upload_enable=YES   #允许匿名用户上传文件,默认未启用。安全起见,实际环境中不能随意启用
          即使启用该选项,匿名用户也无法直接上传文件,因为ftp用户对/var/ftp没有写权限,妥当的做法是在/var/ftp目录下创建子目录,然后让该子目录对ftp用户开放写权限,将文件上传至该子目录
          例如:mkdir /var/ftp/upload
              setfacl -m u:ftp:rwx /var/ftp/upload
        anon_mkdir_write_enable=YES   #允许匿名用户创建目录,默认未启用
        anon_other_write_enable=YES   #允许匿名用户删除文件,默认未启用
        anon_umask=022   #可控制匿名用户上传文件的权限
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
[iyunv@node2 ~]# vim /etc/vsftpd/vsftpd.conf
...
# Allow anonymous FTP? (Beware - allowed by default if you comment this out).
anonymous_enable=YES
#
# Uncomment this to allow local users to log in.
local_enable=YES
#
# Uncomment this to enable any form of FTP write command.
write_enable=YES
#
# Default umask for local users is 077. You may wish to change this to 022,
# if your users expect that (022 is used by most other ftpd's)
local_umask=022    #可以控制本地用户上传文件的默认权限
#
# Uncomment this to allow the anonymous FTP user to upload files. This only
# has an effect if the above global write enable is activated. Also, you will
# obviously need to create a directory writable by the FTP user.
anon_upload_enable=YES   #允许匿名用户上传
anon_other_write_enable=YES   #允许匿名用户删除文件
#
# Uncomment this if you want the anonymous FTP user to be able to create
# new directories.
anon_mkdir_write_enable=YES   #允许匿名用户创建目录
#
# Activate directory messages - messages given to remote users when they
# go into a certain directory.
dirmessage_enable=YES    #用户访问某个目录时可给其反馈一些信息(.message)
...
[iyunv@node2 ~]# service vsftpd reload
Shutting down vsftpd:                                      [  OK  ]
Starting vsftpd for vsftpd:                                [  OK  ]
[iyunv@node2 ~]# ftp 192.168.30.20
Connected to 192.168.30.20 (192.168.30.20).
220 (vsFTPd 2.2.2)
Name (192.168.30.20:root): ftp
331 Please specify the password.
Password:
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> lcd /etc   #切换本地客户端的目录
Local directory now /etc
ftp> put fstab   #上传文件
local: fstab remote: fstab
227 Entering Passive Mode (192,168,30,20,136,83).
553 Could not create file.
ftp> bye
221 Goodbye.
[iyunv@node2 ~]# ll /var/ftp
total 4
drwxr-xr-x 2 root root 4096 Jul 24 08:49 pub
[iyunv@node2 ~]# mkdir /var/ftp/upload
[iyunv@node2 ~]# setfacl -m u:ftp:rwx /var/ftp/upload
[iyunv@node2 ~]# ftp 192.168.30.20
Connected to 192.168.30.20 (192.168.30.20).
220 (vsFTPd 2.2.2)
Name (192.168.30.20:root): ftp
331 Please specify the password.
Password:
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> cd upload
250 Directory successfully changed.
ftp> lcd /etc
Local directory now /etc
ftp> put grub.conf
local: grub.conf remote: grub.conf
227 Entering Passive Mode (192,168,30,20,246,175).
150 Ok to send data.
226 Transfer complete.
769 bytes sent in 8.1e-05 secs (9493.83 Kbytes/sec)
ftp> put fstab
local: fstab remote: fstab
227 Entering Passive Mode (192,168,30,20,217,153).
150 Ok to send data.
226 Transfer complete.
881 bytes sent in 0.000101 secs (8722.77 Kbytes/sec)
ftp> ls
227 Entering Passive Mode (192,168,30,20,126,145).
150 Here comes the directory listing.
-rw-------    1 14       50            881 Nov 21 21:17 fstab
-rw-------    1 14       50            769 Nov 21 21:19 grub.conf
226 Directory send OK.
ftp> delete grub.conf
250 Delete operation successful.
ftp> ls
227 Entering Passive Mode (192,168,30,20,84,157).
150 Here comes the directory listing.
-rw-------    1 14       50            881 Nov 21 21:17 fstab
226 Directory send OK.
ftp> get fstab   #下载文件
local: fstab remote: fstab
227 Entering Passive Mode (192,168,30,20,188,150).
550 Failed to open file.    #提示无法打开文件,检查发现文件的权限是600
ftp> bye
221 Goodbye.
[iyunv@node2 ~]# chmod 644 /var/ftp/upload/fstab
[iyunv@node2 ~]# vim /etc/vsftpd/vsftpd.conf
...
anon_umask=022    #添加该项,使匿名用户上传文件的权限为644(666-022)
...
[iyunv@node2 ~]# service vsftpd reload
Shutting down vsftpd:                                      [  OK  ]
Starting vsftpd for vsftpd:                                [  OK  ]
[iyunv@node2 ~]# ftp 192.168.30.20
Connected to 192.168.30.20 (192.168.30.20).
220 (vsFTPd 2.2.2)
Name (192.168.30.20:root): ftp
331 Please specify the password.
Password:
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> cd upload
250 Directory successfully changed.
ftp> lcd /etc
Local directory now /etc
ftp> put grub.conf
local: grub.conf remote: grub.conf
227 Entering Passive Mode (192,168,30,20,152,4).
150 Ok to send data.
226 Transfer complete.
769 bytes sent in 9.8e-05 secs (7846.94 Kbytes/sec)
ftp> ls
227 Entering Passive Mode (192,168,30,20,160,211).
150 Here comes the directory listing.
-rw-r--r--    1 14       50            881 Nov 21 21:17 fstab
-rw-r--r--    1 14       50            769 Nov 22 16:21 grub.conf   #新上传文件的默认权限已为644
226 Directory send OK.
ftp> lcd /root
Local directory now /root
ftp> get grub.conf
local: grub.conf remote: grub.conf
227 Entering Passive Mode (192,168,30,20,140,191).
150 Opening BINARY mode data connection for grub.conf (769 bytes).
226 Transfer complete.   #成功下载
769 bytes received in 5.1e-05 secs (15078.43 Kbytes/sec)
ftp> exit
221 Goodbye.



   2、本地用户的配置:
        local_enable=YES
        write_enable=YES
        local_umask=022
        锁定所有的ftp本地用户于其家目录中:
           chroot_local_user=YES   #默认未启用
        锁定文件中指定的ftp本地用户于其家目录中:
           chroot_list_enable=YES
           chroot_list_file=/etc/vsftpd/chroot_list
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
[iyunv@node2 ~]# vim /etc/vsftpd/vsftpd.conf
...
chroot_list_enable=YES
# (default follows)
chroot_list_file=/etc/vsftpd/chroot_list
...
[iyunv@node2 ~]# vim /etc/vsftpd/chroot_list

wittgenstein
[iyunv@node2 ~]# service vsftpd reload
Shutting down vsftpd:                                      [  OK  ]
Starting vsftpd for vsftpd:                                [  OK  ]
[iyunv@node2 ~]# ftp 192.168.30.20
Connected to 192.168.30.20 (192.168.30.20).
220 (vsFTPd 2.2.2)
Name (192.168.30.20:root): wittgenstein
331 Please specify the password.
Password:
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> pwd
257 "/"    #显示已被锁
ftp> bye
221 Goodbye.
[iyunv@node2 ~]# ftp 192.168.30.20
Connected to 192.168.30.20 (192.168.30.20).
220 (vsFTPd 2.2.2)
Name (192.168.30.20:root): tesla
331 Please specify the password.
Password:
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> pwd
257 "/home/tesla"



   3、日志:
        xferlog_enable=YES   #是否启用传输日志
        xferlog_std_format=YES
        xferlog_file=/var/log/xferlog(需手动创建)
   4、改变上传文件的属主:
        chown_uploads=YES
        chown_username=whoever
   5、 用户登录控制
      ①vsftpd使用pam完成用户认证,其用到的pam配置文件:
         pam_service_name=vsftpd (/etc/pam.d/vsftpd)
         /etc/vsftpd/ftpusers  #黑名单
      ②是否启用控制用户登录的列表文件:
         userlist_enable=YES(默认文件为/etc/vsftpd/user_list)
         userlist_deny=YES(黑名单)/NO(白名单)
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
[iyunv@node2 ~]# cat /etc/pam.d/vsftpd
#%PAM-1.0
session    optional     pam_keyinit.so    force revoke
auth       required  pam_listfile.so item=user sense=deny file=/etc/vsftpd/ftpusers onerr=succeed
auth       required  pam_shells.so
auth       include   password-auth
account    include  password-auth
session    required     pam_loginuid.so
session    include  password-auth
[iyunv@node2 ~]# vim /etc/vsftpd/vsftpd.conf
...
pam_service_name=vsftpd
userlist_enable=YES
userlist_deny=YES
...
[iyunv@node2 ~]# vim /etc/vsftpd/ftpusers
...
games
nobody
tesla   #将用户tesla加入黑名单
[iyunv@node2 ~]# vim /etc/vsftpd/user_list
...
games
nobody
wittgenstein    #添加该用户
[iyunv@node2 ~]# service vsftpd reload
Shutting down vsftpd:                                      [  OK  ]
Starting vsftpd for vsftpd:                                [  OK  ]
[iyunv@node2 ~]# ftp 192.168.30.20
Connected to 192.168.30.20 (192.168.30.20).
220 (vsFTPd 2.2.2)
Name (192.168.30.20:root): tesla
331 Please specify the password.
Password:
530 Login incorrect.
Login failed.
ftp> bye
221 Goodbye.
[iyunv@node2 ~]# ftp 192.168.30.20
Connected to 192.168.30.20 (192.168.30.20).
220 (vsFTPd 2.2.2)
Name (192.168.30.20:root): wittgenstein
530 Permission denied.
Login failed.
ftp> bye
221 Goodbye.



   6、连接限制:
        max_clients:最大并发连接数
        max_per_ip:每个IP可同时发起的并发请求数
   7、传输速率:
        anon_max_rate:匿名用户的最大传输速率,单位是“字节/秒”;
        local_max_rate:本地用户的最大传输速率
   8、虚拟用户:
        所有的虚拟用户会被统一映射为一个指定的本地用户帐号,访问的共享位置即为此本地用户帐号的家目录
        各虚拟用户可被赋予不同的访问权限,通过匿名用户的权限控制参数进行指定
        虚拟用户的账号存储方式:
          ⑴存于文件中:
               奇数行为用户名
               偶数行为密码
               此文件需要被编码为hash格式
          ⑵存储于关系型数据库中的表中:
               即时查询数据库完成用户认证
               pam要依赖于pam_mysql(由epel源提供)
                   yum -y install pam_mysql
               ①在数据中创建虚拟用户帐号
                   mysql> creat database vsftpd;
                   mysql> grant select onvsftpd.* to vsftpd@'192.168.30.0' identified by 'ftpwd';
                   mysql> flush privileges;
                   mysql> use vsftpd;
                   mysql> create tableusers (
                          id intAUTO_INCREMENT NOT NULL,
                          name char(20) binaryNOT NULL,
                          password char(48)binary NOT NULL,
                          primary key(id)
                        );
                  mysql> insert intousers (name,password) values ('tom',password('magedu'));   # 安全起见,应该使用mysql的内置函数password()加密密码后存储
               ②建立pam认证所需文件
                   vim /etc/pam.d/vsftpd.mysql
                   添加如下两行:
                     auth required /lib64/security/pam_mysql.so user=vsftpd passwd=ftpwd host=192.168.30.20(mysql主机地址) db=vsftpd table=users usercolumn=name passwdcolumn=password crypt=2
                     account required/lib64/security/pam_mysql.so user=vsftpd passwd=ftpwd host=192.168.30.20 db=vsftpd table=users usercolumn=name passwdcolumn=password crypt=2    # crypt的值依mysql存储的虚拟用户密码是否加密及加密方式不同而不同,具体规则可查看/usr/share/doc/pam_mysql-0.7/README
            ③建立虚拟用户映射的本地用户及对应的目录
                    useradd -s /sbin/nologin -d /var/ftproot vuser
                    chmod go+rx /var/ftproot
            ④修改vsftpd的配置文件,使其适用mysql认证
                    确保/etc/vsftpd.conf中已经启用了如下选项:
                       anonymous_enable=YES
                       local_enable=YES
                       write_enable=YES
                       anon_upload_enable=NO
                       anon_mkdir_write_enable=NO
                       chroot_local_user=YES
                    添加以下选项:
                       guest_enable=YES    #启用虚拟用户
                       guest_username=vuser   #指定映射到哪个本地用户
                       pam_service_name=vsftpd.mysql
            ⑤配置虚拟用户具有不同的访问权限
                    vsftpd可以在配置文件目录中为每个虚拟用户提供单独的配置文件以定义其ftp服务访问权限,每个虚拟用户的配置文件名同虚拟用户的用户名。配置文件目录可以是任意未使用的目录,只需要在主配置文件vsftpd.con中指定其路径及名称即可
                    vim/etc/vsftpd/vsftpd.conf
                      添加选项:
                        user_config_dir=/etc/vsftpd/vusers-config
                    mkdir/etc/vsftpd/vusers_config/
                    cd/etc/vsftpd/vusers_config
                    touch tom
                    虚拟用户对vsftpd服务的访问权限是通过匿名用户的相关指令进行的。比如,要让用户tom具有上传文件的权限,可编辑/etc/vsftpd/vusers_config/tom,在其中添加:
                       anon_upload_enable={YES/NO}
                       anon_mkdir_write_enable={YES/NO}
                       anon_other_write_enable={YES/NO}
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
[iyunv@node2 ~]# yum -y install pam_mysql
...
Installed:
  pam_mysql.x86_64 1:0.7-0.12.rc1.el6                                                                    

Dependency Installed:
  mysql-libs.x86_64 0:5.1.73-5.el6_6                                                                     

Complete!
[iyunv@node2 ~]# rpm -ql pam_mysql
/lib64/security/pam_mysql.so
/usr/share/doc/pam_mysql-0.7
/usr/share/doc/pam_mysql-0.7/COPYING
/usr/share/doc/pam_mysql-0.7/CREDITS
/usr/share/doc/pam_mysql-0.7/ChangeLog
/usr/share/doc/pam_mysql-0.7/NEWS
/usr/share/doc/pam_mysql-0.7/README

[iyunv@node2 ~]# mysql
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 2
Server version: 5.5.36-MariaDB-log MariaDB Server

Copyright (c) 2000, 2014, Oracle, Monty Program Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> create database vsftpd;
Query OK, 1 row affected (0.17 sec)

MariaDB [(none)]> use vsftpd
Database changed
MariaDB [vsftpd]> create table users (id int auto_increment not null primary key,name char(20) binary not null,password char(48) binary not null);
Query OK, 0 rows affected (0.51 sec)

MariaDB [vsftpd]> insert into users (name,password) values ('tom',password('magedu')),('jerry',password('linux'));
Query OK, 2 row affected (0.31 sec)

MariaDB [vsftpd]> grant select on vsftpd.* to vsftpd@localhost identified by 'ftpwd';
# 本例中vsftpd和mysqld位于同一主机上,故授权通过本机登录,实际环境中,它们可能位于不同主机上,应按需授权
Query OK, 0 rows affected (0.19 sec)

MariaDB [vsftpd]> flush privileges;
Query OK, 0 rows affected (0.04 sec)

MariaDB [vsftpd]> exit
Bye
[iyunv@node2 ~]# vim /etc/pam.d/vsftpd.mysql

auth required /lib64/security/pam_mysql.so user=vsftpd passwd=ftpwd host=localhost db=vsftpd table=users usercolumn=name passwdcolumn=password crypt=2
account required /lib64/security/pam_mysql.so user=vsftpd passwd=ftpwd host=localhost db=vsftpd table=users usercolumn=name passwdcolumn=password crypt=2

[iyunv@node2 ~]# useradd -s /sbin/nologin -d /var/ftproot vuser
[iyunv@node2 ~]# ls -ld /var/ftproot
drwx------ 4 vuser vuser 4096 Nov 22 14:51 /var/ftproot
[iyunv@node2 ~]# chmod go+rx /var/ftproot
[iyunv@node2 ~]# ls -ld /var/ftproot
drwxr-xr-x 4 vuser vuser 4096 Nov 22 14:51 /var/ftproot
[iyunv@node2 ~]# vim /etc/vsftpd/vsftpd.conf
...
#anon_upload_enable=YES   #禁用这几项
#anon_other_write_enable=YES
#anon_mkdir_write_enable=YES
...
pam_service_name=vsftpd.mysql   #重新指定pam认证配置文件
...
guest_enable=YES    #允许虚拟用户登录
guest_username=vuser
user_config_dir=/etc/vsftpd/vusers-config

[iyunv@node2 ~]# mkdir /etc/vsftpd/vusers-config
[iyunv@node2 ~]# vim /etc/vsftpd/vusers-config/tom

anon_upload_enable=YES
anon_mkdir_write_enable=YES
anon_other_write_enable=YES

[iyunv@node2 ~]# service vsftpd reload
Shutting down vsftpd:                                      [  OK  ]
Starting vsftpd for vsftpd:                                [  OK  ]
[iyunv@node2 ~]# ftp 192.168.30.20
Connected to 192.168.30.20 (192.168.30.20).
220 (vsFTPd 2.2.2)
Name (192.168.30.20:root): jerry
331 Please specify the password.
Password:
530 Login incorrect.   #提示登录错误
Login failed.
ftp> exit
221 Goodbye.
[iyunv@node2 ~]# tail /var/log/secure    #查看日志
...
Nov 22 16:32:55 node2 vsftpd[36754]: pam_mysql - MySQL error (Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2))

[iyunv@node2 ~]# vim /etc/my.cnf
#当前主机上的mysql服务程序是通过二进制格式安装的,其socket路径默认不是/var/lib/mysql/mysql.sock
...
[client]
#password       = your_password
port            = 3306
#socket          = /tmp/mysql.sock
socket          = /var/lib/mysql/mysql.sock   #修改socket路径

# Here follows entries for some specific programs

# The MariaDB server
[mysqld]
port            = 3306
#socket          = /tmp/mysql.sock
socket          = /var/lib/mysql/mysql.sock   #修改socket路径
...

[iyunv@node2 ~]# service mysqld restart
Shutting down MySQL. SUCCESS!
Starting MySQL.. SUCCESS!
[iyunv@node2 ~]# ftp 192.168.30.20
Connected to 192.168.30.20 (192.168.30.20).
220 (vsFTPd 2.2.2)
Name (192.168.30.20:root): jerry
331 Please specify the password.
Password:
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> pwd
257 "/"
ftp> lcd /etc
Local directory now /etc
ftp> put fstab
local: fstab remote: fstab
227 Entering Passive Mode (192,168,30,20,242,54).
550 Permission denied.   #没有给用户jerry开放上传权限
ftp> exit
221 Goodbye.
[iyunv@node2 ~]# ftp 192.168.30.20
Connected to 192.168.30.20 (192.168.30.20).
220 (vsFTPd 2.2.2)
Name (192.168.30.20:root): tom
331 Please specify the password.
Password:
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> lcd /etc
Local directory now /etc
ftp> put fstab
local: fstab remote: fstab
227 Entering Passive Mode (192,168,30,20,111,120).
150 Ok to send data.
226 Transfer complete.
881 bytes sent in 0.000161 secs (5472.05 Kbytes/sec)
ftp> ls
227 Entering Passive Mode (192,168,30,20,226,131).
150 Here comes the directory listing.
-rw-r--r--    1 502      502           881 Nov 22 10:33 fstab
226 Directory send OK.
ftp> exit
221 Goodbye.




三、ftp的几个客户端工具
  除了以上用到的比较简单的ftp命令外,较常用的ftp客户端工具还有:
  1、lftp:一款优秀的文件传输客户端程序,它支持ftp、ftps、http和https等多种文件传输协议。lftp支持tab自动补全
    用法:lftp [-u USERNAME,PASSWORD] [-p PORT] HOST  #默认端口为21
        也可写成 lftp [USERNAME:PASSWORD@]HOST[:PORT]
    若不指定用户,默认以匿名用户的身份登录
    lftp子命令:
      help:获取帮助
      cd:切换远程服务器上的文件系统目录
      lcd:切换本地文件系统目录
      get FILE:下载
      !COMMAND:执行shell命令,而非ftp命令
      mget FILE1...:下载多个文件,支持使用通配符
      mirror DIR:镜像目录至本地
      put FILE:
      mput FILE1...:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
[iyunv@node2 ~]# lftp 192.168.30.20
lftp 192.168.30.20:~> ls
drwxr-xr-x    2 0        0            4096 Jul 24 00:49 pub
drwxrwxr-x    2 0        0            4096 Nov 22 16:21 upload
lftp 192.168.30.20:/> lcd /tmp
lcd ok, local cwd=/tmp
lftp 192.168.30.20:/> get upload/fstab
881 bytes transferred
lftp 192.168.30.20:/> !ls /tmp
fstab  pear  pulse-KA4qOJJfNGYU  pulse-laPR3wljtejc  pulse-t1pCV51k3BVL  yum.log
lftp 192.168.30.20:/> exit
[iyunv@node2 ~]# lftp -u tom 192.168.30.20   #以指定的用户身份登录
Password:
lftp tom@192.168.30.20:~> ls
-rw-r--r--    1 502      502           881 Nov 22 10:33 fstab




  2、lftpget:通过调用lftp指令下载指定的文件;类似于wget

    用法:lftpget [-c] URL [URL...]
    选项:
       -c:继续之前的下载
    例如:lftpget ftp://192.168.30.20/upload/fstab

  3、axel:是一个HTTP/FTP高速下载工具。支持多线程下载、断点续传,且可以从多个地址或者从一个地址的多个连接来下载同一个文件。
    CentOS官方源和epel源中没有提供该包,需手动下载安装:
      wget -c http://pkgs.repoforge.org/axel/axel-2.4-1.el6.rf.x86_64.rpm
      rpm -ivh axel-2.4-1.el6.rf.x86_64.rpm
    用法:axel[OPTIONS] url1 [url2] [url...]
    选项:
       -n:指定线程数(必须为大于 0 的数字)
       -o:指定另存为目录(必须为本地目录)
       -s:指定下载速度(必须为大于 0 的数字,单位是 bytes/s)
       -q:静默模式,无任何输出信息
       -V:软件版本
       --help:显示帮助信息
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
[iyunv@node2 ~]# wget -c http://pkgs.repoforge.org/axel/axel-2.4-1.el6.rf.x86_64.rpm
...
[iyunv@node2 ~]# rpm -ivh axel-2.4-1.el6.rf.x86_64.rpm
warning: axel-2.4-1.el6.rf.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 6b8d79e6: NOKEY
Preparing...                ########################################### [100%]
   1:axel                   ########################################### [100%]
[iyunv@node2 ~]# axel -n 2 -o /tmp ftp://192.168.30.20/upload/grub.conf
Initializing download: ftp://192.168.30.20/upload/grub.conf
File size: 769 bytes
Opening output file /tmp/grub.conf
Starting download

Connection 0 finished

Downloaded 769 bytes in 0 seconds. (7.46 KB/s)
[iyunv@node2 ~]# ls /tmp
fstab  grub.conf  pear  pulse-KA4qOJJfNGYU  pulse-laPR3wljtejc  pulse-t1pCV51k3BVL  yum.log




四、补充:有关用户认证
     ①nsswitch:name service switch,名称服务解析框架
         随着NIS和DNS的出现,查找用户信息和系统信息就不再是简单地搜索本地,而是使用多种途径来查找。文件/etc/nsswitch.conf(name service switch configuration,名称服务切换配置)规定通过哪些途径以及按照什么顺序通过这些途径来查找特定类型的信息。还可以指定若某个方法奏效抑或失效系统将采取什么动作。
         格式:info:  method [[action]] [method [[action]]...]
         模块:/lib64/libnss*,/usr/lib64/libnss*

     ②pam:pluggable authentication module, 可插拔身份验证模块
         可以让系统管理员决定应用程序如何使用身份验证机制来验证用户的身份。
         PAM并不是将身份验证代码构建到每一个应用程序中去,而是提供共享库,让身份验证代码独立于应用程序代码。验证用户身份的技术不会随着应用程序发生变化。PAM让系统管理员能够修改给定应用程序的身份验证机制,而不需要修改应用程序。
         模块共享库:/lib64/security/
         配置文件:/etc/pam.conf,/etc/pam.d/*
           /etc/pam.d目录中的配置文件描述了每个应用程序的身份验证过程。这些文件的名称通常与它们所服务的应用程序的名称相同或者类似。


运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-169193-1-1.html 上篇帖子: Linux下vsftpd安装以及配置FTP虚拟用户实践 下篇帖子: vsftpd 安装及配置 Internet 服务器 软件
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表