APUE Learning Example Source Code
guowenxue
2019-06-26 157be0b0d4c7d4809cfcafc76235cc18388378c8
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
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
'\" t
.\"     Title: mosquitto.conf
.\"    Author: [see the "Author" section]
.\" Generator: DocBook XSL Stylesheets v1.79.1 <http://docbook.sf.net/>
.\"      Date: 06/18/2019
.\"    Manual: File formats and conventions
.\"    Source: Mosquitto Project
.\"  Language: English
.\"
.TH "MOSQUITTO\&.CONF" "5" "06/18/2019" "Mosquitto Project" "File formats and conventions"
.\" -----------------------------------------------------------------
.\" * Define some portability stuff
.\" -----------------------------------------------------------------
.\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.\" http://bugs.debian.org/507673
.\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html
.\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.ie \n(.g .ds Aq \(aq
.el       .ds Aq '
.\" -----------------------------------------------------------------
.\" * set default formatting
.\" -----------------------------------------------------------------
.\" disable hyphenation
.nh
.\" disable justification (adjust text to left margin only)
.ad l
.\" -----------------------------------------------------------------
.\" * MAIN CONTENT STARTS HERE *
.\" -----------------------------------------------------------------
.SH "NAME"
mosquitto.conf \- the configuration file for mosquitto
.SH "SYNOPSIS"
.HP \w'\fBmosquitto\&.conf\fR\ 'u
\fBmosquitto\&.conf\fR
.SH "DESCRIPTION"
.PP
\fBmosquitto\&.conf\fR
is the configuration file for mosquitto\&. This file can reside anywhere as long as mosquitto can read it\&. By default, mosquitto does not need a configuration file and will use the default values listed below\&. See
\fBmosquitto\fR(8)
for information on how to load a configuration file\&.
.SH "FILE FORMAT"
.PP
All lines with a # as the very first character are treated as a comment\&.
.PP
Configuration lines start with a variable name\&. The variable value is separated from the name by a single space\&.
.SH "AUTHENTICATION"
.PP
The authentication options described below allow a wide range of possibilities in conjunction with the listener options\&. This section aims to clarify the possibilities\&.
.PP
The simplest option is to have no authentication at all\&. This is the default if no other options are given\&. Unauthenticated encrypted support is provided by using the certificate based SSL/TLS based options cafile/capath, certfile and keyfile\&.
.PP
MQTT provides username/password authentication as part of the protocol\&. Use the password_file option to define the valid usernames and passwords\&. Be sure to use network encryption if you are using this option otherwise the username and password will be vulnerable to interception\&. Use the
\fBper_listener_settings\fR
to control whether passwords are required globally or on a per\-listener basis\&.
.PP
When using certificate based encryption there are three options that affect authentication\&. The first is require_certificate, which may be set to true or false\&. If false, the SSL/TLS component of the client will verify the server but there is no requirement for the client to provide anything for the server: authentication is limited to the MQTT built in username/password\&. If require_certificate is true, the client must provide a valid certificate in order to connect successfully\&. In this case, the second and third options, use_identity_as_username and use_subject_as_username, become relevant\&. If set to true, use_identity_as_username causes the Common Name (CN) from the client certificate to be used instead of the MQTT username for access control purposes\&. The password is not used because it is assumed that only authenticated clients have valid certificates\&. This means that any CA certificates you include in cafile or capath will be able to issue client certificates that are valid for connecting to your broker\&. If use_identity_as_username is false, the client must authenticate as normal (if required by password_file) through the MQTT options\&. The same principle applies for the use_subject_as_username option, but the entire certificate subject is used as the username instead of just the CN\&.
.PP
When using pre\-shared\-key based encryption through the psk_hint and psk_file options, the client must provide a valid identity and key in order to connect to the broker before any MQTT communication takes place\&. If use_identity_as_username is true, the PSK identity is used instead of the MQTT username for access control purposes\&. If use_identity_as_username is false, the client may still authenticate using the MQTT username/password if using the password_file option\&.
.PP
Both certificate and PSK based encryption are configured on a per\-listener basis\&.
.PP
Authentication plugins can be created to augment the password_file, acl_file and psk_file options with e\&.g\&. SQL based lookups\&.
.PP
It is possible to support multiple authentication schemes at once\&. A config could be created that had a listener for all of the different encryption options described above and hence a large number of ways of authenticating\&.
.SH "GENERAL OPTIONS"
.PP
\fBacl_file\fR \fIfile path\fR
.RS 4
Set the path to an access control list file\&. If defined, the contents of the file are used to control client access to topics on the broker\&.
.sp
If this parameter is defined then only the topics listed will have access\&. Topic access is added with lines of the format:
.sp
topic [read|write|readwrite] <topic>
.sp
The access type is controlled using "read", "write" or "readwrite"\&. This parameter is optional (unless <topic> includes a space character) \- if not given then the access is read/write\&. <topic> can contain the + or # wildcards as in subscriptions\&.
.sp
The first set of topics are applied to anonymous clients, assuming
\fBallow_anonymous\fR
is true\&. User specific topic ACLs are added after a user line as follows:
.sp
user <username>
.sp
The username referred to here is the same as in
\fBpassword_file\fR\&. It is not the clientid\&.
.sp
It is also possible to define ACLs based on pattern substitution within the topic\&. The form is the same as for the topic keyword, but using pattern as the keyword\&.
.sp
pattern [read|write|readwrite] <topic>
.sp
The patterns available for substition are:
.sp
.RS 4
.ie n \{\
\h'-04'\(bu\h'+03'\c
.\}
.el \{\
.sp -1
.IP \(bu 2.3
.\}
%c to match the client id of the client
.RE
.sp
.RS 4
.ie n \{\
\h'-04'\(bu\h'+03'\c
.\}
.el \{\
.sp -1
.IP \(bu 2.3
.\}
%u to match the username of the client
.RE
.sp
The substitution pattern must be the only text for that level of hierarchy\&. Pattern ACLs apply to all users even if the "user" keyword has previously been given\&.
.sp
Example:
.sp
pattern write sensor/%u/data
.sp
Allow access for bridge connection messages:
.sp
pattern write $SYS/broker/connection/%c/state
.sp
If the first character of a line of the ACL file is a # it is treated as a comment\&.
.sp
Reloaded on reload signal\&. The currently loaded ACLs will be freed and reloaded\&. Existing subscriptions will be affected after the reload\&.
.RE
.PP
\fBallow_anonymous\fR [ true | false ]
.RS 4
Boolean value that determines whether clients that connect without providing a username are allowed to connect\&. If set to
\fIfalse\fR
then another means of connection should be created to control authenticated client access\&.
.sp
Defaults to
\fItrue\fR
if no other security options are set\&. If
\fBpassword_file\fR
or
\fBpsk_file\fR
is set, or if an authentication plugin is loaded which implements username/password or TLS\-PSK checks, then
\fBallow_anonymous\fR
defaults to
\fIfalse\fR\&.
.sp
Reloaded on reload signal\&.
.RE
.PP
\fBallow_duplicate_messages\fR [ true | false ]
.RS 4
If a client is subscribed to multiple subscriptions that overlap, e\&.g\&. foo/# and foo/+/baz , then MQTT expects that when the broker receives a message on a topic that matches both subscriptions, such as foo/bar/baz, then the client should only receive the message once\&.
.sp
Mosquitto keeps track of which clients a message has been sent to in order to meet this requirement\&. This option allows this behaviour to be disabled, which may be useful if you have a large number of clients subscribed to the same set of topics and want to minimise memory usage\&.
.sp
It can be safely set to
\fItrue\fR
if you know in advance that your clients will never have overlapping subscriptions, otherwise your clients must be able to correctly deal with duplicate messages even when then have QoS=2\&.
.sp
Defaults to
\fItrue\fR\&.
.sp
Reloaded on reload signal\&.
.RE
.PP
\fBallow_zero_length_clientid\fR [ true | false ]
.RS 4
MQTT 3\&.1\&.1 allows clients to connect with a zero length client id and have the broker generate a client id for them\&. Use this option to allow/disallow this behaviour\&. Defaults to true\&.
.sp
See also the
\fBauto_id_prefix\fR
option\&.
.sp
Reloaded on reload signal\&.
.RE
.PP
\fBauth_opt_*\fR \fIvalue\fR
.RS 4
Options to be passed to the auth plugin\&. See the specific plugin instructions\&.
.RE
.PP
\fBauth_plugin\fR \fIfile path\fR
.RS 4
Specify an external module to use for authentication and access control\&. This allows custom username/password and access control functions to be created\&.
.sp
Can be specified multiple times to load multiple plugins\&. The plugins will be processed in the order that they are specified\&.
.sp
If
\fBpassword_file\fR, or
\fBacl_file\fR
are used in the config file alongsize
\fBauth_plugin\fR, the plugin checks will run after the built in checks\&.
.sp
Not currently reloaded on reload signal\&.
.RE
.PP
\fBauth_plugin_deny_special_chars\fR [ true | false ]
.RS 4
If
\fItrue\fR
then before an ACL check is made, the username/client id of the client needing the check is searched for the presence of either a \*(Aq+\*(Aq or \*(Aq#\*(Aq character\&. If either of these characters is found in either the username or client id, then the ACL check is denied before it is sent to the plugin\&.
.sp
This check prevents the case where a malicious user could circumvent an ACL check by using one of these characters as their username or client id\&. This is the same issue as was reported with mosquitto itself as CVE\-2017\-7650\&.
.sp
If you are entirely sure that the plugin you are using is not vulnerable to this attack (i\&.e\&. if you never use usernames or client ids in topics) then you can disable this extra check and hence have all ACL checks delivered to your plugin by setting this option to
\fIfalse\fR\&.
.sp
Defaults to
\fItrue\fR\&.
.sp
Not currently reloaded on reload signal\&.
.RE
.PP
\fBauto_id_prefix\fR \fIprefix\fR
.RS 4
If
\fBallow_zero_length_clientid\fR
is
\fItrue\fR, this option allows you to set a string that will be prefixed to the automatically generated client ids to aid visibility in logs\&. Defaults to
\fBauto\-\fR\&.
.sp
Reloaded on reload signal\&.
.RE
.PP
\fBautosave_interval\fR \fIseconds\fR
.RS 4
The number of seconds that mosquitto will wait between each time it saves the in\-memory database to disk\&. If set to 0, the in\-memory database will only be saved when mosquitto exits or when receiving the SIGUSR1 signal\&. Note that this setting only has an effect if persistence is enabled\&. Defaults to 1800 seconds (30 minutes)\&.
.sp
Reloaded on reload signal\&.
.RE
.PP
\fBautosave_on_changes\fR [ true | false ]
.RS 4
If
\fItrue\fR, mosquitto will count the number of subscription changes, retained messages received and queued messages and if the total exceeds
\fBautosave_interval\fR
then the in\-memory database will be saved to disk\&. If
\fIfalse\fR, mosquitto will save the in\-memory database to disk by treating
\fBautosave_interval\fR
as a time in seconds\&.
.sp
Reloaded on reload signal\&.
.RE
.PP
\fBcheck_retain_source\fR [ true | false ]
.RS 4
This option affects the scenario when a client subscribes to a topic that has retained messages\&. It is possible that the client that published the retained message to the topic had access at the time they published, but that access has been subsequently removed\&. If
\fBcheck_retain_source\fR
is set to true, the default, the source of a retained message will be checked for access rights before it is republished\&. When set to false, no check will be made and the retained message will always be published\&.
.sp
This option applies globally, regardless of the
\fBper_listener_settings\fR
option\&.
.RE
.PP
\fBclientid_prefixes\fR \fIprefix\fR
.RS 4
If defined, only clients that have a clientid with a prefix that matches clientid_prefixes will be allowed to connect to the broker\&. For example, setting "secure\-" here would mean a client "secure\-client" could connect but another with clientid "mqtt" couldn\*(Aqt\&. By default, all client ids are valid\&.
.sp
Reloaded on reload signal\&. Note that currently connected clients will be unaffected by any changes\&.
.RE
.PP
\fBconnection_messages\fR [ true | false ]
.RS 4
If set to
\fItrue\fR, the log will include entries when clients connect and disconnect\&. If set to
\fIfalse\fR, these entries will not appear\&.
.sp
Reloaded on reload signal\&.
.RE
.PP
\fBinclude_dir\fR \fIdir\fR
.RS 4
External configuration files may be included by using the include_dir option\&. This defines a directory that will be searched for config files\&. All files that end in \*(Aq\&.conf\*(Aq will be loaded as a configuration file\&. It is best to have this as the last option in the main file\&. This option will only be processed from the main configuration file\&. The directory specified must not contain the main configuration file\&.
.sp
The configuration files in
\fBinclude_dir\fR
are loaded in case sensitive alphabetical order, with the upper case of each letter ordered before the lower case of the same letter\&.
.PP
\fBExample\ \&Load Order for include_dir.\ \&\fR
Given the files
\fIb\&.conf\fR,
\fIA\&.conf\fR,
\fI01\&.conf\fR,
\fIa\&.conf\fR,
\fIB\&.conf\fR, and
\fI00\&.conf\fR
inside
\fBinclude_dir\fR, the config files would be loaded in this order:
.sp
.if n \{\
.RS 4
.\}
.nf
00\&.conf
01\&.conf
A\&.conf
a\&.conf
B\&.conf
b\&.conf
.fi
.if n \{\
.RE
.\}
 
If this option is used multiple times, then each
\fBinclude_dir\fR
option is processed completely in the order that they are written in the main configuration file\&.
.PP
\fBExample\ \&Load Order for Multiple include_dir.\ \&\fR
Assuming a directory
\fIone\&.d\fR
containing files
\fIB\&.conf\fR
and
\fIC\&.conf\fR, and a second directory
\fItwo\&.d\fR
containing files
\fIA\&.conf\fR
and
\fID\&.conf\fR, and a config:
.sp
.if n \{\
.RS 4
.\}
.nf
include_dir one\&.d
include_dir two\&.d
.fi
.if n \{\
.RE
.\}
.sp
Then the config files would be loaded in this order:
.sp
.if n \{\
.RS 4
.\}
.nf
# files from one\&.d
B\&.conf
C\&.conf
# files from two\&.d
A\&.conf
D\&.conf
.fi
.if n \{\
.RE
.\}
.RE
.PP
\fBlog_dest\fR \fIdestinations\fR
.RS 4
Send log messages to a particular destination\&. Possible destinations are:
\fBstdout\fR
\fBstderr\fR
\fBsyslog\fR
\fBtopic\fR\&.
.sp
\fBstdout\fR
and
\fBstderr\fR
log to the console on the named output\&.
.sp
\fBsyslog\fR
uses the userspace syslog facility which usually ends up in /var/log/messages or similar and topic logs to the broker topic \*(Aq$SYS/broker/log/<severity>\*(Aq, where severity is one of D, E, W, N, I, M which are debug, error, warning, notice, information and message\&. Message type severity is used by the subscribe and unsubscribe log_type options and publishes log messages at $SYS/broker/log/M/subscribe and $SYS/broker/log/M/unsubscribe\&.
.sp
The
\fBfile\fR
destination requires an additional parameter which is the file to be logged to, e\&.g\&. "log_dest file /var/log/mosquitto\&.log"\&. The file will be closed and reopened when the broker receives a HUP signal\&. Only a single file destination may be configured\&.
.sp
Use "log_dest none" if you wish to disable logging\&. Defaults to stderr\&. This option may be specified multiple times\&.
.sp
Note that if the broker is running as a Windows service it will default to "log_dest none" and neither stdout nor stderr logging is available\&.
.sp
Reloaded on reload signal\&.
.RE
.PP
\fBlog_facility\fR \fIlocal facility\fR
.RS 4
If using syslog logging (not on Windows), messages will be logged to the "daemon" facility by default\&. Use the
\fBlog_facility\fR
option to choose which of local0 to local7 to log to instead\&. The option value should be an integer value, e\&.g\&. "log_facility 5" to use local5\&.
.RE
.PP
\fBlog_timestamp\fR [ true | false ]
.RS 4
Boolean value, if set to
\fItrue\fR
a timestamp value will be added to each log entry\&. The default is
\fItrue\fR\&.
.sp
Reloaded on reload signal\&.
.RE
.PP
\fBlog_timestamp_format\fR \fIformat\fR
.RS 4
Set the format of the log timestamp\&. If left unset, this is the number of seconds since the Unix epoch\&. This option is a free text string which will be passed to the strftime function as the format specifier\&. To get an ISO 8601 datetime, for example:
.sp
.if n \{\
.RS 4
.\}
.nf
log_timestamp_format %Y\-%m\-%dT%H:%M:%S
                    
.fi
.if n \{\
.RE
.\}
.sp
Reloaded on reload signal\&.
.RE
.PP
\fBlog_type\fR \fItypes\fR
.RS 4
Choose types of messages to log\&. Possible types are:
\fIdebug\fR,
\fIerror\fR,
\fIwarning\fR,
\fInotice\fR,
\fIinformation\fR,
\fIsubscribe\fR,
\fIunsubscribe\fR,
\fIwebsockets\fR,
\fInone\fR,
\fIall\fR\&.
.sp
Defaults to
\fIerror\fR,
\fIwarning\fR,
\fInotice \fRand
\fIinformation\fR\&. This option may be specified multiple times\&. Note that the
\fIdebug \fRtype (used for decoding incoming/outgoing network packets) is never logged in topics\&.
.sp
Reloaded on reload signal\&.
.RE
.PP
\fBmax_inflight_bytes\fR \fIcount\fR
.RS 4
QoS 1 and 2 messages will be allowed in flight until this byte limit is reached\&. Defaults to 0\&. (No limit) See also the
\fBmax_inflight_messages\fR
option\&.
.sp
Reloaded on reload signal\&.
.RE
.PP
\fBmax_inflight_messages\fR \fIcount\fR
.RS 4
The maximum number of QoS 1 or 2 messages that can be in the process of being transmitted simultaneously\&. This includes messages currently going through handshakes and messages that are being retried\&. Defaults to 20\&. Set to 0 for no maximum\&. If set to 1, this will guarantee in\-order delivery of messages\&.
.sp
Reloaded on reload signal\&.
.RE
.PP
\fBmax_keepalive\fR \fIvalue\fR
.RS 4
For MQTT v5 clients, it is possible to have the server send a "server keepalive" value that will override the keepalive value set by the client\&. This is intended to be used as a mechanism to say that the server will disconnect the client earlier than it anticipated, and that the client should use the new keepalive value\&. The max_keepalive option allows you to specify that clients may only connect with keepalive less than or equal to this value, otherwise they will be sent a server keepalive telling them to use max_keepalive\&. This only applies to MQTT v5 clients\&. The maximum value allowable, and default value, is 65535\&. Do not set below 10 seconds\&.
.sp
Reloaded on reload signal\&.
.RE
.PP
\fBmax_packet_size\fR \fIvalue\fR
.RS 4
For MQTT v5 clients, it is possible to have the server send a "maximum packet size" value that will instruct the client it will not accept MQTT packets with size greater than
\fBvalue\fR
bytes\&. This applies to the full MQTT packet, not just the payload\&. Setting this option to a positive value will set the maximum packet size to that number of bytes\&. If a client sends a packet which is larger than this value, it will be disconnected\&. This applies to all clients regardless of the protocol version they are using, but v3\&.1\&.1 and earlier clients will of course not have received the maximum packet size information\&. Defaults to no limit\&.
.sp
Setting below 20 bytes is forbidden because it is likely to interfere with normal client operation even with small payloads\&.
.sp
Reloaded on reload signal\&.
.RE
.PP
\fBmax_queued_bytes\fR \fIcount\fR
.RS 4
QoS 1 and 2 messages above those currently in\-flight will be queued (per client) until this limit is exceeded\&. Defaults to 0\&. (No maximum) See also the
\fBmax_queued_messages\fR
option\&. If both max_queued_messages and max_queued_bytes are specified, packets will be queued until the first limit is reached\&.
.sp
Reloaded on reload signal\&.
.RE
.PP
\fBmax_queued_messages\fR \fIcount\fR
.RS 4
The maximum number of QoS 1 or 2 messages to hold in the queue (per client) above those messages that are currently in flight\&. Defaults to 100\&. Set to 0 for no maximum (not recommended)\&. See also the
\fBqueue_qos0_messages\fR
and
\fBmax_queued_bytes\fR
options\&.
.sp
Reloaded on reload signal\&.
.RE
.PP
\fBmemory_limit\fR \fIlimit\fR
.RS 4
This option sets the maximum number of heap memory bytes that the broker will allocate, and hence sets a hard limit on memory use by the broker\&. Memory requests that exceed this value will be denied\&. The effect will vary depending on what has been denied\&. If an incoming message is being processed, then the message will be dropped and the publishing client will be disconnected\&. If an outgoing message is being sent, then the individual message will be dropped and the receiving client will be disconnected\&. Defaults to no limit\&.
.sp
This option is only available if memory tracking support is compiled in\&.
.sp
Reloaded on reload signal\&. Setting to a lower value and reloading will not result in memory being freed\&.
.RE
.PP
\fBmessage_size_limit\fR \fIlimit\fR
.RS 4
This option sets the maximum publish payload size that the broker will allow\&. Received messages that exceed this size will not be accepted by the broker\&. The default value is 0, which means that all valid MQTT messages are accepted\&. MQTT imposes a maximum payload size of 268435455 bytes\&.
.RE
.PP
\fBpassword_file\fR \fIfile path\fR
.RS 4
Set the path to a password file\&. If defined, the contents of the file are used to control client access to the broker\&. The file can be created using the
\fBmosquitto_passwd\fR(1)
utility\&. If mosquitto is compiled without TLS support (it is recommended that TLS support is included), then the password file should be a text file with each line in the format "username:password", where the colon and password are optional but recommended\&. If
\fBallow_anonymous\fR
is set to
\fIfalse\fR, only users defined in this file will be able to connect\&. Setting
\fBallow_anonymous\fR
to
\fItrue\fR
when
\fIpassword_file\fRis defined is valid and could be used with acl_file to have e\&.g\&. read only guest/anonymous accounts and defined users that can publish\&.
.sp
Reloaded on reload signal\&. The currently loaded username and password data will be freed and reloaded\&. Clients that are already connected will not be affected\&.
.sp
See also
\fBmosquitto_passwd\fR(1)\&.
.RE
.PP
\fBper_listener_settings\fR [ true | false ]
.RS 4
If
\fItrue\fR, then authentication and access control settings will be controlled on a per\-listener basis\&. The following options are affected:
.sp
\fBpassword_file\fR,
\fBacl_file\fR,
\fBpsk_file\fR,
\fBallow_anonymous\fR,
\fBallow_zero_length_clientid\fR,
\fBauth_plugin\fR,
\fBauth_opt_*\fR,
\fBauto_id_prefix\fR\&.
.sp
Note that if set to true, then a durable client (i\&.e\&. with clean session set to false) that has disconnected will use the ACL settings defined for the listener that it was most recently connected to\&.
.sp
The default behaviour is for this to be set to
\fIfalse\fR, which maintains the settings behaviour from previous versions of mosquitto\&.
.sp
Reloaded on reload signal\&.
.RE
.PP
\fBpersistence\fR [ true | false ]
.RS 4
If
\fItrue\fR, connection, subscription and message data will be written to the disk in mosquitto\&.db at the location dictated by persistence_location\&. When mosquitto is restarted, it will reload the information stored in mosquitto\&.db\&. The data will be written to disk when mosquitto closes and also at periodic intervals as defined by autosave_interval\&. Writing of the persistence database may also be forced by sending mosquitto the SIGUSR1 signal\&. If
\fIfalse\fR, the data will be stored in memory only\&. Defaults to
\fIfalse\fR\&.
.sp
The persistence file may change its format in a new version\&. The broker can currently read all old formats, but will only save in the latest format\&. It should always be safe to upgrade, but cautious users may wish to take a copy of the persistence file before installing a new version so that they can roll back to an earlier version if necessary\&.
.sp
Reloaded on reload signal\&.
.RE
.PP
\fBpersistence_file\fR \fIfile name\fR
.RS 4
The filename to use for the persistent database\&. Defaults to mosquitto\&.db\&.
.sp
Reloaded on reload signal\&.
.RE
.PP
\fBpersistence_location\fR \fIpath\fR
.RS 4
The path where the persistence database should be stored\&. Must end in a trailing slash\&. If not given, then the current directory is used\&.
.sp
Reloaded on reload signal\&.
.RE
.PP
\fBpersistent_client_expiration\fR \fIduration\fR
.RS 4
This option allows persistent clients (those with clean session set to false) to be removed if they do not reconnect within a certain time frame\&. This is a non\-standard option\&. As far as the MQTT spec is concerned, persistent clients persist forever\&.
.sp
Badly designed clients may set clean session to false whilst using a randomly generated client id\&. This leads to persistent clients that will never reconnect\&. This option allows these clients to be removed\&.
.sp
The expiration period should be an integer followed by one of h d w m y for hour, day, week, month and year respectively\&. For example:
.sp
.RS 4
.ie n \{\
\h'-04'\(bu\h'+03'\c
.\}
.el \{\
.sp -1
.IP \(bu 2.3
.\}
persistent_client_expiration 2m
.RE
.sp
.RS 4
.ie n \{\
\h'-04'\(bu\h'+03'\c
.\}
.el \{\
.sp -1
.IP \(bu 2.3
.\}
persistent_client_expiration 14d
.RE
.sp
.RS 4
.ie n \{\
\h'-04'\(bu\h'+03'\c
.\}
.el \{\
.sp -1
.IP \(bu 2.3
.\}
persistent_client_expiration 1y
.RE
.sp
As this is a non\-standard option, the default if not set is to never expire persistent clients\&.
.sp
Reloaded on reload signal\&.
.RE
.PP
\fBpid_file\fR \fIfile path\fR
.RS 4
Write a pid file to the file specified\&. If not given (the default), no pid file will be written\&. If the pid file cannot be written, mosquitto will exit\&. This option only has an effect is mosquitto is run in daemon mode\&.
.sp
If mosquitto is being automatically started by an init script it will usually be required to write a pid file\&. This should then be configured as e\&.g\&. /var/run/mosquitto\&.pid
.sp
Not reloaded on reload signal\&.
.RE
.PP
\fBpsk_file\fR \fIfile path\fR
.RS 4
Set the path to a pre\-shared\-key file\&. This option requires a listener to be have PSK support enabled\&. If defined, the contents of the file are used to control client access to the broker\&. Each line should be in the format "identity:key", where the key is a hexadecimal string with no leading "0x"\&. A client connecting to a listener that has PSK support enabled must provide a matching identity and PSK to allow the encrypted connection to proceed\&.
.sp
Reloaded on reload signal\&. The currently loaded identity and key data will be freed and reloaded\&. Clients that are already connected will not be affected\&.
.RE
.PP
\fBqueue_qos0_messages\fR [ true | false ]
.RS 4
Set to
\fItrue\fR
to queue messages with QoS 0 when a persistent client is disconnected\&. These messages are included in the limit imposed by max_queued_messages\&. Defaults to
\fIfalse\fR\&.
.sp
Note that the MQTT v3\&.1\&.1 spec states that only QoS 1 and 2 messages should be saved in this situation so this is a non\-standard option\&.
.sp
Reloaded on reload signal\&.
.RE
.PP
\fBretain_available\fR [ true | false ]
.RS 4
If set to false, then retained messages are not supported\&. Clients that send a message with the retain bit will be disconnected if this option is set to false\&. Defaults to true\&.
.sp
Reloaded on reload signal\&.
.RE
.PP
\fBretained_persistence\fR [ true | false ]
.RS 4
This is a synonym of the
\fBpersistence\fR
option\&.
.sp
Reloaded on reload signal\&.
.RE
.PP
\fBset_tcp_nodelay\fR [ true | false ]
.RS 4
If set to true, the TCP_NODELAY option will be set on client sockets to disable Nagle\*(Aqs algorithm\&. This has the effect of reducing latency of some messages at potentially increasing the number of TCP packets being sent\&. Defaults to false\&.
.sp
Reloaded on reload signal\&.
.RE
.PP
\fBsys_interval\fR \fIseconds\fR
.RS 4
The integer number of seconds between updates of the $SYS subscription hierarchy, which provides status information about the broker\&. If unset, defaults to 10 seconds\&.
.sp
Set to 0 to disable publishing the $SYS hierarchy completely\&.
.sp
Reloaded on reload signal\&.
.RE
.PP
\fBupgrade_outgoing_qos\fR [ true | false ]
.RS 4
The MQTT specification requires that the QoS of a message delivered to a subscriber is never upgraded to match the QoS of the subscription\&. Enabling this option changes this behaviour\&. If
\fBupgrade_outgoing_qos\fR
is set
\fItrue\fR, messages sent to a subscriber will always match the QoS of its subscription\&. This is a non\-standard option not provided for by the spec\&. Defaults to
\fIfalse\fR\&.
.sp
Reloaded on reload signal\&.
.RE
.PP
\fBuser\fR \fIusername\fR
.RS 4
When run as root, change to this user and its primary group on startup\&. If mosquitto is unable to change to this user and group, it will exit with an error\&. The user specified must have read/write access to the persistence database if it is to be written\&. If run as a non\-root user, this setting has no effect\&. Defaults to mosquitto\&.
.sp
This setting has no effect on Windows and so you should run mosquitto as the user you wish it to run as\&.
.sp
Not reloaded on reload signal\&.
.RE
.SH "LISTENERS"
.PP
The network ports that mosquitto listens on can be controlled using listeners\&. The default listener options can be overridden and further listeners can be created\&.
.SS "General Options"
.PP
\fBbind_address\fR \fIaddress\fR
.RS 4
Listen for incoming network connections on the specified IP address/hostname only\&. This is useful to restrict access to certain network interfaces\&. To restrict access to mosquitto to the local host only, use "bind_address localhost"\&. This only applies to the default listener\&. Use the listener variable to control other listeners\&.
.sp
Not reloaded on reload signal\&.
.RE
.PP
\fBbind_interface\fR \fIdevice\fR
.RS 4
Listen for incoming network connections only on the specified interface\&. This is similar to the
\fBbind_address\fR
option but is useful when an interface has multiple addresses or the address may change\&.
.sp
It is valid to use this option together with
\fBbind_address\fR
for the default listener, or the
\fIbind address/host\fR
part of the
\fBlistener\fR
definition\&. Care should be taken to ensure that the address being bound to is on the interface being bound to\&. If you set the
\fBbind_interface\fR
to be
\fIeth0\fR, and
\fBbind_address\fR
to
\fI127\&.0\&.0\&.1\fR, then the broker will start correctly but you will be unable to connect\&.
.sp
This option is currently only available on Linux, and requires elevated privileges\&.
.sp
Not reloaded on reload signal\&.
.RE
.PP
\fBhttp_dir\fR \fIdirectory\fR
.RS 4
When a listener is using the websockets protocol, it is possible to serve http data as well\&. Set
\fBhttp_dir\fR
to a directory which contains the files you wish to serve\&. If this option is not specified, then no normal http connections will be possible\&.
.sp
Not reloaded on reload signal\&.
.RE
.PP
\fBlistener\fR \fIport\fR \fI[bind address/host]\fR
.RS 4
Listen for incoming network connection on the specified port\&. A second optional argument allows the listener to be bound to a specific ip address/hostname\&. If this variable is used and neither the global
\fBbind_address\fR
nor
\fBport\fR
options are used then the default listener will not be started\&.
.sp
The
\fBbind address/host\fR
option allows this listener to be bound to a specific IP address by passing an IP address or hostname\&. For websockets listeners, it is only possible to pass an IP address here\&.
.sp
This option may be specified multiple times\&. See also the
\fBmount_point\fR
option\&.
.sp
Not reloaded on reload signal\&.
.RE
.PP
\fBmax_connections\fR \fIcount\fR
.RS 4
Limit the total number of clients connected for the current listener\&. Set to
\-1
to have "unlimited" connections\&. Note that other limits may be imposed that are outside the control of mosquitto\&. See e\&.g\&.
\fBlimits.conf\fR(5)\&.
.sp
Not reloaded on reload signal\&.
.RE
.PP
\fBmaximum_qos\fR \fIcount\fR
.RS 4
Limit the QoS value allowed when using this listener\&. Defaults to 2, which means any QoS can be used\&. Set to 0 or 1 to limit to those QoS values\&. This makes use of an MQTT v5 feature to notify clients of the limitation\&. MQTT v3\&.1\&.1 clients will not be aware of the limitation\&. Clients publshing to this listener with a too\-high QoS will be disconnected\&.
.sp
Not reloaded on reload signal\&.
.RE
.PP
\fBmax_topic_alias\fR \fInumber\fR
.RS 4
This option sets the maximum number topic aliases that an MQTT v5 client is allowed to create\&. It applies per listener\&. Defaults to 10\&. Set to 0 to disallow topic aliases\&.
.sp
Not reloaded on reload signal\&.
.RE
.PP
\fBmount_point\fR \fItopic prefix\fR
.RS 4
This option is used with the listener option to isolate groups of clients\&. When a client connects to a listener which uses this option, the string argument is attached to the start of all topics for this client\&. This prefix is removed when any messages are sent to the client\&. This means a client connected to a listener with mount point
\fIexample\fR
can only see messages that are published in the topic hierarchy
\fIexample\fR
and below\&.
.sp
Not reloaded on reload signal\&.
.RE
.PP
\fBport\fR \fIport number\fR
.RS 4
Set the network port for the default listener to listen on\&. Defaults to 1883\&.
.sp
Not reloaded on reload signal\&.
.RE
.PP
\fBprotocol\fR \fIvalue\fR
.RS 4
Set the protocol to accept for this listener\&. Can be
\fBmqtt\fR, the default, or
\fBwebsockets\fR
if available\&.
.sp
Websockets support is currently disabled by default at compile time\&. Certificate based TLS may be used with websockets, except that only the
\fBcafile\fR,
\fBcertfile\fR,
\fBkeyfile\fR
and
\fBciphers\fR
options are supported\&.
.sp
Not reloaded on reload signal\&.
.RE
.PP
\fBsocket_domain\fR [ ipv4 | ipv6 ]
.RS 4
By default, a listener will attempt to listen on all supported IP protocol versions\&. If you do not have an IPv4 or IPv6 interface you may wish to disable support for either of those protocol versions\&. In particular, note that due to the limitations of the websockets library, it will only ever attempt to open IPv6 sockets if IPv6 support is compiled in, and so will fail if IPv6 is not available\&.
.sp
Set to
\fBipv4\fR
to force the listener to only use IPv4, or set to
\fBipv6\fR
to force the listener to only use IPv6\&. If you want support for both IPv4 and IPv6, then do not use the
\fBsocket_domain\fR
option\&.
.sp
Not reloaded on reload signal\&.
.RE
.PP
\fBuse_username_as_clientid\fR [ true | false ]
.RS 4
Set
\fBuse_username_as_clientid\fR
to true to replace the clientid that a client connected with with its username\&. This allows authentication to be tied to the clientid, which means that it is possible to prevent one client disconnecting another by using the same clientid\&. Defaults to false\&.
.sp
If a client connects with no username it will be disconnected as not authorised when this option is set to true\&. Do not use in conjunction with
\fBclientid_prefixes\fR\&.
.sp
See also
\fBuse_identity_as_username\fR\&.
.sp
Not reloaded on reload signal\&.
.RE
.PP
\fBwebsockets_log_level\fR \fIlevel\fR
.RS 4
Change the websockets logging level\&. This is a global option, it is not possible to set per listener\&. This is an integer that is interpreted by libwebsockets as a bit mask for its lws_log_levels enum\&. See the libwebsockets documentation for more details\&.
.sp
To use this option,
\fBlog_type websockets\fR
must also be enabled\&. Defaults to 0\&.
.RE
.PP
\fBwebsockets_headers_size\fR \fIsize\fR
.RS 4
Change the websockets headers size\&. This is a global option, it is not possible to set per listener\&. This option sets the size of the buffer used in the libwebsockets library when reading HTTP headers\&. If you are passing large header data such as cookies then you may need to increase this value\&. If left unset, or set to 0, then the default of 1024 bytes will be used\&.
.RE
.SS "Certificate based SSL/TLS Support"
.PP
The following options are available for all listeners to configure certificate based SSL support\&. See also "Pre\-shared\-key based SSL/TLS support"\&.
.PP
\fBcafile\fR \fIfile path\fR
.RS 4
At least one of
\fBcafile\fR
or
\fBcapath\fR
must be provided to allow SSL support\&.
.sp
\fBcafile\fR
is used to define the path to a file containing the PEM encoded CA certificates that are trusted\&.
.RE
.PP
\fBcapath\fR \fIdirectory path\fR
.RS 4
At least one of
\fBcafile\fR
or
\fBcapath\fR
must be provided to allow SSL support\&.
.sp
\fBcapath\fR
is used to define a directory that contains PEM encoded CA certificates that are trusted\&. For
\fBcapath\fR
to work correctly, the certificates files must have "\&.pem" as the file ending and you must run "openssl rehash <path to capath>" each time you add/remove a certificate\&.
.RE
.PP
\fBcertfile\fR \fIfile path\fR
.RS 4
Path to the PEM encoded server certificate\&.
.RE
.PP
\fBciphers\fR \fIcipher:list\fR
.RS 4
The list of allowed ciphers, each separated with a colon\&. Available ciphers can be obtained using the "openssl ciphers" command\&.
.RE
.PP
\fBcrlfile\fR \fIfile path\fR
.RS 4
If you have
\fBrequire_certificate\fR
set to
\fItrue\fR, you can create a certificate revocation list file to revoke access to particular client certificates\&. If you have done this, use crlfile to point to the PEM encoded revocation file\&.
.RE
.PP
\fBdhparamfile\fR \fIfile path\fR
.RS 4
To allow the use of ephemeral DH key exchange, which provides forward security, the listener must load DH parameters\&. This can be specified with the dhparamfile option\&. The dhparamfile can be generated with the command e\&.g\&.
.sp
.if n \{\
.RS 4
.\}
.nf
openssl dhparam \-out dhparam\&.pem 2048
.fi
.if n \{\
.RE
.\}
.RE
.PP
\fBkeyfile\fR \fIfile path\fR
.RS 4
Path to the PEM encoded keyfile\&.
.RE
.PP
\fBrequire_certificate\fR [ true | false ]
.RS 4
By default an SSL/TLS enabled listener will operate in a similar fashion to a https enabled web server, in that the server has a certificate signed by a CA and the client will verify that it is a trusted certificate\&. The overall aim is encryption of the network traffic\&. By setting
\fBrequire_certificate\fR
to
\fItrue\fR, the client must provide a valid certificate in order for the network connection to proceed\&. This allows access to the broker to be controlled outside of the mechanisms provided by MQTT\&.
.RE
.PP
\fBtls_engine\fR \fIengine\fR
.RS 4
A valid openssl engine id\&. These can be listed with openssl engine command\&.
.RE
.PP
\fBtls_engine_kpass_sha1\fR \fIengine_kpass_sha1\fR
.RS 4
SHA1 of the private key password when using an TLS engine\&. Some TLS engines such as the TPM engine may require the use of a password in order to be accessed\&. This option allows a hex encoded SHA1 hash of the password to the engine directly, instead of the user being prompted for the password\&.
.RE
.PP
\fBtls_keyform\fR [ pem | engine ]
.RS 4
Specifies the type of private key in use when making TLS connections\&.\&. This can be "pem" or "engine"\&. This parameter is useful when a TPM module is being used and the private key has been created with it\&. Defaults to "pem", which means normal private key files are used\&.
.RE
.PP
\fBtls_version\fR \fIversion\fR
.RS 4
Configure the version of the TLS protocol to be used for this listener\&. Possible values are
\fItlsv1\&.3\fR,
\fItlsv1\&.2\fR
and
\fItlsv1\&.1\fR\&. If left unset, the default of allowing all of TLS v1\&.3, v1\&.2 and v1\&.1 is used\&.
.RE
.PP
\fBuse_identity_as_username\fR [ true | false ]
.RS 4
If
\fBrequire_certificate\fR
is
\fItrue\fR, you may set
\fBuse_identity_as_username\fR
to
\fItrue\fR
to use the CN value from the client certificate as a username\&. If this is
\fItrue\fR, the
\fBpassword_file\fR
option will not be used for this listener\&.
.sp
This takes priority over
\fBuse_subject_as_username\fR
if both are set to
\fItrue\fR\&.
.sp
See also
\fBuse_subject_as_username\fR
.RE
.PP
\fBuse_subject_as_username\fR [ true | false ]
.RS 4
If
\fBrequire_certificate\fR
is
\fItrue\fR, you may set
\fBuse_subject_as_username\fR
to
\fItrue\fR
to use the complete subject value from the client certificate as a username\&. If this is
\fItrue\fR, the
\fBpassword_file\fR
option will not be used for this listener\&.
.sp
The subject will be generated in a form similar to
\fBCN=test client,OU=Production,O=Server,L=Nottingham,ST=Nottinghamshire,C=GB\fR\&.
.sp
See also
\fBuse_identity_as_username\fR
.RE
.SS "Pre\-shared\-key based SSL/TLS Support"
.PP
The following options are available for all listeners to configure pre\-shared\-key based SSL support\&. See also "Certificate based SSL/TLS support"\&.
.PP
\fBciphers\fR \fIcipher:list\fR
.RS 4
When using PSK, the encryption ciphers used will be chosen from the list of available PSK ciphers\&. If you want to control which ciphers are available, use this option\&. The list of available ciphers can be optained using the "openssl ciphers" command and should be provided in the same format as the output of that command\&.
.RE
.PP
\fBpsk_hint\fR \fIhint\fR
.RS 4
The
\fBpsk_hint\fR
option enables pre\-shared\-key support for this listener and also acts as an identifier for this listener\&. The hint is sent to clients and may be used locally to aid authentication\&. The hint is a free form string that doesn\*(Aqt have much meaning in itself, so feel free to be creative\&.
.sp
If this option is provided, see
\fBpsk_file\fR
to define the pre\-shared keys to be used or create a security plugin to handle them\&.
.RE
.PP
\fBtls_version\fR \fIversion\fR
.RS 4
Configure the version of the TLS protocol to be used for this listener\&. Possible values are
\fItlsv1\&.3\fR,
\fItlsv1\&.2\fR
and
\fItlsv1\&.1\fR\&. If left unset, the default of allowing all of TLS v1\&.3, v1\&.2 and v1\&.1 is used\&.
.RE
.PP
\fBuse_identity_as_username\fR [ true | false ]
.RS 4
Set
\fBuse_identity_as_username\fR
to have the psk identity sent by the client used as its username\&. The username will be checked as normal, so
\fBpassword_file\fR
or another means of authentication checking must be used\&. No password will be used\&.
.RE
.SH "CONFIGURING BRIDGES"
.PP
Multiple bridges (connections to other brokers) can be configured using the following variables\&.
.PP
Bridges cannot currently be reloaded on reload signal\&.
.PP
\fBaddress\fR \fIaddress[:port]\fR \fI[address[:port]]\fR, \fBaddresses\fR \fIaddress[:port]\fR \fI[address[:port]]\fR
.RS 4
Specify the address and optionally the port of the bridge to connect to\&. This must be given for each bridge connection\&. If the port is not specified, the default of 1883 is used\&.
.sp
If you use an IPv6 address, then the port is not optional\&.
.sp
Multiple host addresses can be specified on the address config\&. See the
\fBround_robin\fR
option for more details on the behaviour of bridges with multiple addresses\&.
.RE
.PP
\fBbridge_attempt_unsubscribe\fR [ true | false ]
.RS 4
If a bridge has topics that have "out" direction, the default behaviour is to send an unsubscribe request to the remote broker on that topic\&. This means that changing a topic direction from "in" to "out" will not keep receiving incoming messages\&. Sending these unsubscribe requests is not always desirable, setting
\fBbridge_attempt_unsubscribe\fR
to
\fIfalse\fR
will disable sending the unsubscribe request\&. Defaults to
\fItrue\fR\&.
.RE
.PP
\fBbridge_protocol_version\fR \fIversion\fR
.RS 4
Set the version of the MQTT protocol to use with for this bridge\&. Can be one of
\fImqttv31\fR
or
\fImqttv311\fR\&. Defaults to
\fImqttv31\fR\&.
.RE
.PP
\fBcleansession\fR [ true | false ]
.RS 4
Set the clean session option for this bridge\&. Setting to
\fIfalse\fR
(the default), means that all subscriptions on the remote broker are kept in case of the network connection dropping\&. If set to
\fItrue\fR, all subscriptions and messages on the remote broker will be cleaned up if the connection drops\&. Note that setting to
\fItrue\fR
may cause a large amount of retained messages to be sent each time the bridge reconnects\&.
.sp
If you are using bridges with
\fBcleansession\fR
set to
\fIfalse\fR
(the default), then you may get unexpected behaviour from incoming topics if you change what topics you are subscribing to\&. This is because the remote broker keeps the subscription for the old topic\&. If you have this problem, connect your bridge with
\fBcleansession\fR
set to
\fItrue\fR, then reconnect with cleansession set to
\fIfalse\fR
as normal\&.
.RE
.PP
\fBconnection\fR \fIname\fR
.RS 4
This variable marks the start of a new bridge connection\&. It is also used to give the bridge a name which is used as the client id on the remote broker\&.
.RE
.PP
\fBkeepalive_interval\fR \fIseconds\fR
.RS 4
Set the number of seconds after which the bridge should send a ping if no other traffic has occurred\&. Defaults to 60\&. A minimum value of 5 seconds is allowed\&.
.RE
.PP
\fBidle_timeout\fR \fIseconds\fR
.RS 4
Set the amount of time a bridge using the lazy start type must be idle before it will be stopped\&. Defaults to 60 seconds\&.
.RE
.PP
\fBlocal_clientid\fR \fIid\fR
.RS 4
Set the clientid to use on the local broker\&. If not defined, this defaults to
\fBlocal\&.<remote_clientid>\fR\&. If you are bridging a broker to itself, it is important that local_clientid and remote_clientid do not match\&.
.RE
.PP
\fBlocal_password\fR \fIpassword\fR
.RS 4
Configure the password to be used when connecting this bridge to the local broker\&. This may be important when authentication and ACLs are being used\&.
.RE
.PP
\fBlocal_username\fR \fIusername\fR
.RS 4
Configure the username to be used when connecting this bridge to the local broker\&. This may be important when authentication and ACLs are being used\&.
.RE
.PP
\fBnotifications\fR [ true | false ]
.RS 4
If set to
\fItrue\fR, publish notification messages to the local and remote brokers giving information about the state of the bridge connection\&. Retained messages are published to the topic $SYS/broker/connection/<remote_clientid>/state unless otherwise set with
\fBnotification_topic\fRs\&. If the message is 1 then the connection is active, or 0 if the connection has failed\&. Defaults to
\fItrue\fR\&.
.sp
This uses the Last Will and Testament (LWT) feature\&.
.RE
.PP
\fBnotifications_local_only\fR [ true | false ]
.RS 4
If set to
\fItrue\fR, only publish notification messages to the local broker giving information about the state of the bridge connection\&. Defaults to
\fIfalse\fR\&.
.RE
.PP
\fBnotification_topic\fR \fItopic\fR
.RS 4
Choose the topic on which notifications will be published for this bridge\&. If not set the messages will be sent on the topic $SYS/broker/connection/<remote_clientid>/state\&.
.RE
.PP
\fBremote_clientid\fR \fIid\fR
.RS 4
Set the client id for this bridge connection\&. If not defined, this defaults to \*(Aqname\&.hostname\*(Aq, where name is the connection name and hostname is the hostname of this computer\&.
.sp
This replaces the old "clientid" option to avoid confusion with local/remote sides of the bridge\&. "clientid" remains valid for the time being\&.
.RE
.PP
\fBremote_password\fR \fIvalue\fR
.RS 4
Configure a password for the bridge\&. This is used for authentication purposes when connecting to a broker that supports MQTT v3\&.1 and up and requires a username and/or password to connect\&. This option is only valid if a remote_username is also supplied\&.
.sp
This replaces the old "password" option to avoid confusion with local/remote sides of the bridge\&. "password" remains valid for the time being\&.
.RE
.PP
\fBremote_username\fR \fIname\fR
.RS 4
Configure a username for the bridge\&. This is used for authentication purposes when connecting to a broker that supports MQTT v3\&.1 and up and requires a username and/or password to connect\&. See also the
\fBremote_password\fR
option\&.
.sp
This replaces the old "username" option to avoid confusion with local/remote sides of the bridge\&. "username" remains valid for the time being\&.
.RE
.PP
\fBrestart_timeout\fR \fIbase cap\fR, \fBrestart_timeout\fR \fIconstant\fR
.RS 4
Set the amount of time a bridge using the automatic start type will wait until attempting to reconnect\&.
.sp
This option can be configured to use a constant delay time in seconds, or to use a backoff mechanism based on "Decorrelated Jitter", which adds a degree of randomness to when the restart occurs, starting at the base and increasing up to the cap\&. Set a constant timeout of 20 seconds:
.sp
.if n \{\
.RS 4
.\}
.nf
restart_timeout 20
.fi
.if n \{\
.RE
.\}
.sp
Set backoff with a base (start value) of 10 seconds and a cap (upper limit) of 60 seconds:
.sp
.if n \{\
.RS 4
.\}
.nf
restart_timeout 10 30
.fi
.if n \{\
.RE
.\}
.sp
Defaults to jitter with a base of 5 seconds and cap of 30 seconds\&.
.RE
.PP
\fBround_robin\fR [ true | false ]
.RS 4
If the bridge has more than one address given in the address/addresses configuration, the round_robin option defines the behaviour of the bridge on a failure of the bridge connection\&. If round_robin is
\fIfalse\fR, the default value, then the first address is treated as the main bridge connection\&. If the connection fails, the other secondary addresses will be attempted in turn\&. Whilst connected to a secondary bridge, the bridge will periodically attempt to reconnect to the main bridge until successful\&.
.sp
If round_robin is
\fItrue\fR, then all addresses are treated as equals\&. If a connection fails, the next address will be tried and if successful will remain connected until it fails\&.
.RE
.PP
\fBstart_type\fR [ automatic | lazy | once ]
.RS 4
Set the start type of the bridge\&. This controls how the bridge starts and can be one of three types:
\fIautomatic\fR,
\fIlazy \fRand
\fIonce\fR\&. Note that RSMB provides a fourth start type "manual" which isn\*(Aqt currently supported by mosquitto\&.
.sp
\fIautomatic\fR
is the default start type and means that the bridge connection will be started automatically when the broker starts and also restarted after a short delay (30 seconds) if the connection fails\&.
.sp
Bridges using the
\fIlazy\fR
start type will be started automatically when the number of queued messages exceeds the number set with the
\fBthreshold\fR
option\&. It will be stopped automatically after the time set by the
\fBidle_timeout\fR
parameter\&. Use this start type if you wish the connection to only be active when it is needed\&.
.sp
A bridge using the
\fIonce\fR
start type will be started automatically when the broker starts but will not be restarted if the connection fails\&.
.RE
.PP
\fBthreshold\fR \fIcount\fR
.RS 4
Set the number of messages that need to be queued for a bridge with lazy start type to be restarted\&. Defaults to 10 messages\&.
.RE
.PP
\fBtopic\fR \fIpattern\fR [[[ out | in | both ] qos\-level] local\-prefix remote\-prefix]
.RS 4
Define a topic pattern to be shared between the two brokers\&. Any topics matching the pattern (which may include wildcards) are shared\&. The second parameter defines the direction that the messages will be shared in, so it is possible to import messages from a remote broker using
\fIin\fR, export messages to a remote broker using
\fIout\fR
or share messages in both directions\&. If this parameter is not defined, the default of
\fIout\fR
is used\&. The QoS level defines the publish/subscribe QoS level used for this topic and defaults to 0\&.
.sp
The
\fIlocal\-prefix\fR
and
\fIremote\-prefix\fR
options allow topics to be remapped when publishing to and receiving from remote brokers\&. This allows a topic tree from the local broker to be inserted into the topic tree of the remote broker at an appropriate place\&.
.sp
For incoming topics, the bridge will prepend the pattern with the remote prefix and subscribe to the resulting topic on the remote broker\&. When a matching incoming message is received, the remote prefix will be removed from the topic and then the local prefix added\&.
.sp
For outgoing topics, the bridge will prepend the pattern with the local prefix and subscribe to the resulting topic on the local broker\&. When an outgoing message is processed, the local prefix will be removed from the topic then the remote prefix added\&.
.sp
When using topic mapping, an empty prefix can be defined using the place marker
\fI""\fR\&. Using the empty marker for the topic itself is also valid\&. The table below defines what combination of empty or value is valid\&. The
\fBFull Local Topic\fR
and
\fBFull Remote Topic\fR
show the resulting topics that would be used on the local and remote ends of the bridge\&. For example, for the first table row if you publish to
\fBL/topic\fR
on the local broker, then the remote broker will receive a message on the topic
\fBR/topic\fR\&.
.TS
allbox tab(:);
lB lB lB lB lB lB.
T{
\fIPattern\fR
T}:T{
\fILocal Prefix\fR
T}:T{
\fIRemote Prefix\fR
T}:T{
\fIValidity\fR
T}:T{
\fIFull Local Topic\fR
T}:T{
\fIFull Remote Topic\fR
T}
.T&
l l l l l l
l l l l l l
l l l l l l
l l l l l l
l l l l l l
l l l l l l
l l l l l l
l l l l l l.
T{
pattern
T}:T{
L/
T}:T{
R/
T}:T{
valid
T}:T{
L/pattern
T}:T{
R/pattern
T}
T{
pattern
T}:T{
L/
T}:T{
""
T}:T{
valid
T}:T{
L/pattern
T}:T{
pattern
T}
T{
pattern
T}:T{
""
T}:T{
R/
T}:T{
valid
T}:T{
pattern
T}:T{
R/pattern
T}
T{
pattern
T}:T{
""
T}:T{
""
T}:T{
valid (no remapping)
T}:T{
pattern
T}:T{
pattern
T}
T{
""
T}:T{
local
T}:T{
remote
T}:T{
valid (remap single local topic to remote)
T}:T{
local
T}:T{
remote
T}
T{
""
T}:T{
local
T}:T{
""
T}:T{
invalid
T}:T{
\ \&
T}:T{
\ \&
T}
T{
""
T}:T{
""
T}:T{
remote
T}:T{
invalid
T}:T{
\ \&
T}:T{
\ \&
T}
T{
""
T}:T{
""
T}:T{
""
T}:T{
invalid
T}:T{
\ \&
T}:T{
\ \&
T}
.TE
.sp 1
To remap an entire topic tree, use e\&.g\&.:
.sp
.if n \{\
.RS 4
.\}
.nf
topic # both 2 local/topic/ remote/topic/
.fi
.if n \{\
.RE
.\}
.sp
This option can be specified multiple times per bridge\&.
.sp
Care must be taken to ensure that loops are not created with this option\&. If you are experiencing high CPU load from a broker, it is possible that you have a loop where each broker is forever forwarding each other the same messages\&.
.sp
See also the
\fBcleansession\fR
option if you have messages arriving on unexpected topics when using incoming topics\&.
.PP
\fBExample\ \&Bridge Topic Remapping.\ \&\fR
The configuration below connects a bridge to the broker at
\fBtest\&.mosquitto\&.org\fR\&. It subscribes to the remote topic
\fB$SYS/broker/clients/total\fR
and republishes the messages received to the local topic
\fBtest/mosquitto/org/clients/total\fR
.sp
.if n \{\
.RS 4
.\}
.nf
connection test\-mosquitto\-org
address test\&.mosquitto\&.org
cleansession true
topic clients/total in 0 test/mosquitto/org $SYS/broker/
.fi
.if n \{\
.RE
.\}
.RE
.PP
\fBtry_private\fR [ true | false ]
.RS 4
If try_private is set to
\fItrue\fR, the bridge will attempt to indicate to the remote broker that it is a bridge not an ordinary client\&. If successful, this means that loop detection will be more effective and that retained messages will be propagated correctly\&. Not all brokers support this feature so it may be necessary to set
\fBtry_private\fR
to
\fIfalse\fR
if your bridge does not connect properly\&.
.sp
Defaults to
\fItrue\fR\&.
.RE
.SS "SSL/TLS Support"
.PP
The following options are available for all bridges to configure SSL/TLS support\&.
.PP
\fBbridge_alpn\fR \fIalpn\fR
.RS 4
Configure the application layer protocol negotiation option for the TLS session\&. Useful for brokers that support both websockets and MQTT on the same port\&.
.RE
.PP
\fBbridge_cafile\fR \fIfile path\fR
.RS 4
One of
\fBbridge_cafile\fR
or
\fBbridge_capath\fR
must be provided to allow SSL/TLS support\&.
.sp
bridge_cafile is used to define the path to a file containing the PEM encoded CA certificates that have signed the certificate for the remote broker\&.
.RE
.PP
\fBbridge_capath\fR \fIfile path\fR
.RS 4
One of
\fBbridge_capath\fR
or
\fBbridge_capath\fR
must be provided to allow SSL/TLS support\&.
.sp
bridge_capath is used to define the path to a directory containing the PEM encoded CA certificates that have signed the certificate for the remote broker\&. For bridge_capath to work correctly, the certificate files must have "\&.crt" as the file ending and you must run "openssl rehash <path to bridge_capath>" each time you add/remove a certificate\&.
.RE
.PP
\fBbridge_certfile\fR \fIfile path\fR
.RS 4
Path to the PEM encoded client certificate for this bridge, if required by the remote broker\&.
.RE
.PP
\fBbridge_identity\fR \fIidentity\fR
.RS 4
Pre\-shared\-key encryption provides an alternative to certificate based encryption\&. A bridge can be configured to use PSK with the
\fBbridge_identity\fR
and
\fBbridge_psk\fR
options\&. This is the client identity used with PSK encryption\&. Only one of certificate and PSK based encryption can be used on one bridge at once\&.
.RE
.PP
\fBbridge_insecure\fR [ true | false ]
.RS 4
When using certificate based TLS, the bridge will attempt to verify the hostname provided in the remote certificate matches the host/address being connected to\&. This may cause problems in testing scenarios, so
\fBbridge_insecure\fR
may be set to
\fIfalse\fR
to disable the hostname verification\&.
.sp
Setting this option to
\fItrue\fR
means that a malicious third party could potentially inpersonate your server, so it should always be set to
\fIfalse\fR
in production environments\&.
.RE
.PP
\fBbridge_keyfile\fR \fIfile path\fR
.RS 4
Path to the PEM encoded private key for this bridge, if required by the remote broker\&.
.RE
.PP
\fBbridge_psk\fR \fIkey\fR
.RS 4
Pre\-shared\-key encryption provides an alternative to certificate based encryption\&. A bridge can be configured to use PSK with the
\fBbridge_identity\fR
and
\fBbridge_psk\fR
options\&. This is the pre\-shared\-key in hexadecimal format with no "0x"\&. Only one of certificate and PSK based encryption can be used on one bridge at once\&.
.RE
.PP
\fBbridge_require_ocsp\fR [ true | false ]
.RS 4
When set to true, the bridge requires OCSP on the TLS connection it opens as client\&.
.RE
.PP
\fBbridge_tls_version\fR \fIversion\fR
.RS 4
Configure the version of the TLS protocol to be used for this bridge\&. Possible values are
\fItlsv1\&.3\fR,
\fItlsv1\&.2\fR
and
\fItlsv1\&.1\fR\&. Defaults to
\fItlsv1\&.2\fR\&. The remote broker must support the same version of TLS for the connection to succeed\&.
.RE
.SH "FILES"
.PP
mosquitto\&.conf
.SH "BUGS"
.PP
\fBmosquitto\fR
bug information can be found at
\m[blue]\fB\%https://github.com/eclipse/mosquitto/issues\fR\m[]
.SH "SEE ALSO"
\fBmosquitto\fR(8), \fBmosquitto_passwd\fR(1), \fBmosquitto-tls\fR(7), \fBmqtt\fR(7), \fBlimits.conf\fR(5)
.SH "AUTHOR"
.PP
Roger Light
<roger@atchoo\&.org>