aboutsummaryrefslogtreecommitdiff
path: root/documentation/content/en/books/handbook/basics/_index.adoc
blob: 6174c0ade084116f38ee4598ae56bfff7a6eaa88 (plain) (blame)
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
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
---
title: Chapter 3. FreeBSD Basics
part: Part I. Getting Started
prev: books/handbook/bsdinstall
next: books/handbook/ports
description: Basic commands and functionality of the FreeBSD operating system
tags: ["basics", "virtual consoles", "users", "management", "permissions", "directory structure", "disk organization", "mounting", "processes", "daemons", "shell", "editor", "manual pages", "devices"]
showBookMenu: true
weight: 5
path: "/books/handbook/"
aliases: ["/en/books/handbook/consoles/","/en/books/handbook/users-synopsis/","/en/books/handbook/permissions/","/en/books/handbook/dirstructure/","/en/books/handbook/disk-organization/","/en/books/handbook/mount-unmount/","/en/books/handbook/basics-processes/","/en/books/handbook/shells/","/en/books/handbook/editors/","/en/books/handbook/basics-devices/","/en/books/handbook/basics-more-information/"]
---

[[basics]]
= FreeBSD Basics
:doctype: book
:toc: macro
:toclevels: 1
:icons: font
:sectnums:
:sectnumlevels: 6
:sectnumoffset: 3
:partnums:
:source-highlighter: rouge
:experimental:
:images-path: books/handbook/basics/

ifdef::env-beastie[]
ifdef::backend-html5[]
:imagesdir: ../../../../images/{images-path}
endif::[]
ifndef::book[]
include::shared/authors.adoc[]
include::shared/mirrors.adoc[]
include::shared/releases.adoc[]
include::shared/attributes/attributes-{{% lang %}}.adoc[]
include::shared/{{% lang %}}/teams.adoc[]
include::shared/{{% lang %}}/mailing-lists.adoc[]
include::shared/{{% lang %}}/urls.adoc[]
toc::[]
endif::[]
ifdef::backend-pdf,backend-epub3[]
include::../../../../../shared/asciidoctor.adoc[]
endif::[]
endif::[]

ifndef::env-beastie[]
toc::[]
include::../../../../../shared/asciidoctor.adoc[]
endif::[]

[[basics-synopsis]]
== Synopsis

This chapter covers the basic commands and functionality of the FreeBSD operating system.
Much of this material is relevant for any UNIX(R)-like operating system.
New FreeBSD users are encouraged to read through this chapter carefully.

After reading this chapter, you will know:

* How to use and configure virtual consoles.
* How to create and manage users and groups on FreeBSD.
* How UNIX(R) file permissions and FreeBSD file flags work.
* The default FreeBSD file system layout.
* The FreeBSD disk organization.
* How to mount and unmount file systems.
* What processes, daemons, and signals are.
* What a shell is, and how to change the default login environment.
* How to use basic text editors.
* What devices and device nodes are.
* How to read manual pages for more information.

[[consoles]]
== Virtual Consoles and Terminals

Unless FreeBSD has been configured to automatically start a graphical environment during startup, the system will boot into a command line login prompt, as seen in this example:

[source,shell]
....
FreeBSD/amd64 (pc3.example.org) (ttyv0)

login:
....

The first line contains some information about the system.
The `amd64` indicates that the system in this example is running a 64-bit version of FreeBSD.
The hostname is `pc3.example.org`, and `ttyv0` indicates that this is the "system console".
The second line is the login prompt.

Since FreeBSD is a multiuser system, it needs some way to distinguish between different users.
This is accomplished by requiring every user to log into the system before gaining access to the programs on the system.
Every user has a unique "username" and a personal "password".

To log into the system console, type the username that was configured during system installation, as described in crossref:bsdinstall[bsdinstall-addusers,Add Users], and press kbd:[Enter].
Then enter the password associated with the username and press kbd:[Enter].
The password is _not echoed_ for security reasons.

Once the correct password is input, the message of the day (MOTD) will be displayed followed by a command prompt.
Depending upon the shell that was selected when the user was created, this prompt will be a `+#+`, `$`, or `%` character.
The prompt indicates that the user is now logged into the FreeBSD system console and ready to try the available commands.

[[consoles-virtual]]
=== Virtual Consoles

While the system console can be used to interact with the system, a user working from the command line at the keyboard of a FreeBSD system will typically instead log into a virtual console.
This is because system messages are configured by default to display on the system console.
These messages will appear over the command or file that the user is working on, making it difficult to concentrate on the work at hand.

By default, FreeBSD is configured to provide several virtual consoles for inputting commands.
Each virtual console has its own login prompt and shell and it is easy to switch between virtual consoles.
This essentially provides the command line equivalent of having several windows open at the same time in a graphical environment.

The key combinations kbd:[Alt+F1] through kbd:[Alt+F8] have been reserved by FreeBSD for switching between virtual consoles.
Use kbd:[Alt+F1] to switch to the system console (`ttyv0`), kbd:[Alt+F2] to access the first virtual console (`ttyv1`), kbd:[Alt+F3] to access the second virtual console (`ttyv2`), and so on.
When using Xorg as a graphical console, the combination becomes kbd:[Ctrl+Alt+F1] to return to a text-based virtual console.

When switching from one console to the next, FreeBSD manages the screen output.
The result is an illusion of having multiple virtual screens and keyboards that can be used to type commands for FreeBSD to run.
The programs that are launched in one virtual console do not stop running when the user switches to a different virtual console.

Refer to man:kbdcontrol[1], man:vidcontrol[1], man:atkbd[4], man:syscons[4], and man:vt[4] for a more technical description of the FreeBSD console and its keyboard drivers.

In FreeBSD, the number of available virtual consoles is configured in this section of `/etc/ttys`:

[.programlisting]
....
# name    getty                         type  status comments
#
ttyv0   "/usr/libexec/getty Pc"         xterm   on  secure
# Virtual terminals
ttyv1   "/usr/libexec/getty Pc"         xterm   on  secure
ttyv2   "/usr/libexec/getty Pc"         xterm   on  secure
ttyv3   "/usr/libexec/getty Pc"         xterm   on  secure
ttyv4   "/usr/libexec/getty Pc"         xterm   on  secure
ttyv5   "/usr/libexec/getty Pc"         xterm   on  secure
ttyv6   "/usr/libexec/getty Pc"         xterm   on  secure
ttyv7   "/usr/libexec/getty Pc"         xterm   on  secure
ttyv8   "/usr/X11R6/bin/xdm -nodaemon"  xterm   off secure
....

To disable a virtual console, put a comment symbol (`+#+`) at the beginning of the line representing that virtual console.
For example, to reduce the number of available virtual consoles from eight to four, put a `+#+` in front of the last four lines representing virtual consoles `ttyv5` through `ttyv8`.
_Do not_ comment out the line for the system console `ttyv0`.
Note that the last virtual console (`ttyv8`) is used to access the graphical environment if Xorg has been installed and configured as described in crossref:x11[x11,The X Window System].

For a detailed description of every column in this file and the available options for the virtual consoles, refer to man:ttys[5].

[[consoles-singleuser]]
=== Single User Mode

The FreeBSD boot menu provides an option labelled as "Boot Single User".
If this option is selected, the system will boot into a special mode known as "single user mode".
This mode is typically used to repair a system that will not boot or to reset the `root` password when it is not known.
While in single user mode, networking and other virtual consoles are not available.
However, full `root` access to the system is available, and by default, the `root` password is not needed.
For these reasons, physical access to the keyboard is needed to boot into this mode and determining who has physical access to the keyboard is something to consider when securing a FreeBSD system.

The settings which control single user mode are found in this section of `/etc/ttys`:

[.programlisting]
....
# name  getty                           type  status  comments
#
# If console is marked "insecure", then init will ask for the root password
# when going to single-user mode.
console none                            unknown  off  secure
....

By default, the status is set to `secure`.
This assumes that who has physical access to the keyboard is either not important or it is controlled by a physical security policy.
If this setting is changed to `insecure`, the assumption is that the environment itself is insecure because anyone can access the keyboard.
When this line is changed to `insecure`, FreeBSD will prompt for the `root` password when a user selects to boot into single user mode.

[NOTE]
====
_Be careful when changing this setting to `insecure`!_ If the `root` password is forgotten, booting into single user mode is still possible, but may be difficult for someone who is not familiar with the FreeBSD booting process.
====

[[consoles-vidcontrol]]
=== Changing Console Video Modes

The FreeBSD console default video mode may be adjusted to 1024x768, 1280x1024, or any other size supported by the graphics chip and monitor.
To use a different video mode load the `VESA` module:

[source,shell]
....
# kldload vesa
....

To determine which video modes are supported by the hardware, use man:vidcontrol[1].
To get a list of supported video modes issue the following:

[source,shell]
....
# vidcontrol -i mode
....

The output of this command lists the video modes that are supported by the hardware.
To select a new video mode, specify the mode using man:vidcontrol[1] as the `root` user:

[source,shell]
....
# vidcontrol MODE_279
....

If the new video mode is acceptable, it can be permanently set on boot by adding it to `/etc/rc.conf`:

[.programlisting]
....
allscreens_flags="MODE_279"
....

[[users-synopsis]]
== Users and Basic Account Management

FreeBSD allows multiple users to use the computer at the same time.
While only one user can sit in front of the screen and use the keyboard at any one time, any number of users can log in to the system through the network.
To use the system, each user should have their own user account.

This chapter describes:

* The different types of user accounts on a FreeBSD system.
* How to add, remove, and modify user accounts.
* How to set limits to control the resources that users and groups are allowed to access.
* How to create groups and add users as members of a group.

[[users-introduction]]
=== Account Types

Since all access to the FreeBSD system is achieved using accounts and all processes are run by users, user and account management is important.

There are three main types of accounts: system accounts, user accounts, and the superuser account.

[[users-system]]
==== System Accounts

System accounts are used to run services such as DNS, mail, and web servers.
The reason for this is security; if all services ran as the superuser, they could act without restriction.

Examples of system accounts are `daemon`, `operator`, `bind`, `news`, and `www`.

`nobody` is the generic unprivileged system account.
However, the more services that use `nobody`, the more files and processes that user will become associated with, and hence the more privileged that user becomes.

[[users-user]]
==== User Accounts

User accounts are assigned to real people and are used to log in and use the system.
Every person accessing the system should have a unique user account.
This allows the administrator to find out who is doing what and prevents users from clobbering the settings of other users.

Each user can set up their own environment to accommodate their use of the system, by configuring their default shell, editor, key bindings, and language settings.

Every user account on a FreeBSD system has certain information associated with it:

User name::
The user name is typed at the `login:` prompt.
Each user must have a unique user name. 
There are a number of rules for creating valid user names which are documented in man:passwd[5].
It is recommended to use user names that consist of eight or fewer, all lower case characters in order to maintain backwards compatibility with applications.

Password::
Each account has an associated password.

User ID (UID)::
The User ID (UID) is a number used to uniquely identify the user to the FreeBSD system. 
Commands that allow a user name to be specified will first convert it to the UID.
It is recommended to use a UID less than 65535, since higher values may cause compatibility issues with some software.

Group ID (GID)::
The Group ID (GID) is a number used to uniquely identify the primary group that the user belongs to.
Groups are a mechanism for controlling access to resources based on a user's GID rather than their UID.
This can significantly reduce the size of some configuration files and allows users to be members of more than one group.
It is recommended to use a GID of 65535 or lower as higher GIDs may break some software.

Login class::
Login classes are an extension to the group mechanism that provide additional flexibility when tailoring the system to different users.
Login classes are discussed further in crossref:security[users-limiting,Configuring Login Classes].

Password change time::
By default, passwords do not expire.
However, password expiration can be enabled on a per-user basis, forcing some or all users to change their passwords after a certain amount of time has elapsed.

Account expiration time::
By default, FreeBSD does not expire accounts.
When creating accounts that need a limited lifespan, such as student accounts in a school, specify the account expiry date using man:pw[8].
After the expiry time has elapsed, the account cannot be used to log in to the system, although the account's directories and files will remain.

User's full name::
The user name uniquely identifies the account to FreeBSD, but does not necessarily reflect the user's real name.
Similar to a comment, this information can contain spaces, uppercase characters, and be more than 8 characters long.

Home directory::
The home directory is the full path to a directory on the system.
This is the user's starting directory when the user logs in.
A common convention is to put all user home directories under `/home/username` or `/usr/home/username`.
Each user stores their personal files and subdirectories in their own home directory.

User shell::
The shell provides the user's default environment for interacting with the system.
There are many different kinds of shells and experienced users will have their own preferences, which can be reflected in their account settings.

[[users-superuser]]
==== The Superuser Account

The superuser account, usually called `root`, is used to manage the system with no limitations on privileges.
For this reason, it should not be used for day-to-day tasks like sending and receiving mail, general exploration of the system, or programming.

The superuser, unlike other user accounts, can operate without limits, and misuse of the superuser account may result in spectacular disasters.
User accounts are unable to destroy the operating system by mistake, so it is recommended to login as a user account and to only become the superuser when a command requires extra privilege.

Always double and triple-check any commands issued as the superuser, since an extra space or missing character can mean irreparable data loss.

There are several ways to gain superuser privilege.
While one can log in as `root`, this is highly discouraged.

Instead, use man:su[1] to become the superuser.
If `-` is specified when running this command, the user will also inherit the root user's environment.
The user running this command must be in the `wheel` group or else the command will fail.
The user must also know the password for the `root` user account.

In this example, the user only becomes superuser in order to run `make install` as this step requires superuser privilege.
Once the command completes, the user types `exit` to leave the superuser account and return to the privilege of their user account.

.Install a Program As the Superuser
[example]
====
[source,shell]
....
% configure
% make
% su -
Password:
# make install
# exit
%
....
====

The built-in man:su[1] framework works well for single systems or small networks with just one system administrator.
An alternative is to install the package:security/sudo[] package or port.
This software provides activity logging and allows the administrator to configure which users can run which commands as the superuser.

[[users-modifying]]
=== Managing Accounts

FreeBSD provides a variety of different commands to manage user accounts.
The most common commands are summarized in <<users-modifying-utilities>>, followed by some examples of their usage.
See the manual page for each utility for more details and usage examples.

[[users-modifying-utilities]]
.Utilities for Managing User Accounts
[cols="25h,~"]
|===
| Command
| Summary

|man:adduser[8]
|The recommended command-line application for adding new users.

|man:rmuser[8]
|The recommended command-line application for removing users.

|man:chpass[1]
|A flexible tool for changing user database information.

|man:passwd[1]
|The command-line tool to change user passwords.

|man:pw[8]
|A powerful and flexible tool for modifying all aspects of user accounts.

|man:bsdconfig[8]
|A system configuration utility with account management support.
|===

[[users-adduser]]
==== Adding a user

The recommended program for adding new users is man:adduser[8].
When a new user is added, this program automatically updates `/etc/passwd` and `/etc/group`.
It also creates a home directory for the new user, copies in the default configuration files from `/usr/share/skel`, and can optionally mail the new user a welcome message.
This utility must be run as the superuser.

The man:adduser[8] utility is interactive and walks through the steps for creating a new user account.
As seen in <<users-modifying-adduser>>, either input the required information or press kbd:[Return] to accept the default value shown in square brackets.
In this example, the user has been invited into the `wheel` group, allowing them to become the superuser with man:su[1].
When finished, the utility will prompt to either create another user or to exit.

[[users-modifying-adduser]]
.Adding a User on FreeBSD
[example]
====
[source,shell]
....
# adduser
Username: jru
Full name: J. Random User
Uid (Leave empty for default):
Login group [jru]:
Login group is jru. Invite jru into other groups? []: wheel
Login class [default]:
Shell (sh csh tcsh zsh nologin) [sh]: zsh
Home directory [/home/jru]:
Home directory permissions (Leave empty for default):
Use password-based authentication? [yes]:
Use an empty password? (yes/no) [no]:
Use a random password? (yes/no) [no]:
Enter password:
Enter password again:
Lock out the account after creation? [no]:
Username   : jru
Password   : ****
Full Name  : J. Random User
Uid        : 1001
Class      :
Groups     : jru wheel
Home       : /home/jru
Shell      : /usr/local/bin/zsh
Locked     : no
OK? (yes/no): yes
adduser: INFO: Successfully added (jru) to the user database.
Add another user? (yes/no): no
Goodbye!
....
====

[NOTE]
====
Since the password is not echoed when typed, be careful to not mistype the password when creating the user account.
====

[[users-rmuser]]
==== Removing a user

To completely remove a user from the system, run man:rmuser[8] as the superuser.
This command performs the following steps:

[.procedure]
====
. Removes the user's man:crontab[1] entry, if one exists.
. Removes any man:at[1] jobs belonging to the user.
. Sends a SIGKILL signal to all processes owned by the user.
. Removes the user from the system's local password file.
. Removes the user's home directory (if it is owned by the user), including handling of symbolic links in the path to the actual home directory.
. Removes the incoming mail files belonging to the user from `/var/mail`.
. Removes all files owned by the user from `/tmp`, `/var/tmp`, and `/var/tmp/vi.recover`.
. Removes the username from all groups to which it belongs in `/etc/group`. (If a group becomes empty and the group name is the same as the username, the group is removed; this complements man:adduser[8]'s per-user unique groups.)
. Removes all message queues, shared memory segments and semaphores owned by the user.
====

man:rmuser[8] cannot be used to remove superuser accounts since that is almost always an indication of massive destruction.

By default, an interactive mode is used, as shown in the following example.

.`rmuser` Interactive Account Removal
[example]
====
[source,shell]
....
# rmuser jru
Matching password entry:
jru:*:1001:1001::0:0:J. Random User:/home/jru:/usr/local/bin/zsh
Is this the entry you wish to remove? y
Remove user's home directory (/home/jru)? y
Removing user (jru): mailspool home passwd.
....
====

[[users-chpass]]
==== Change user information

Any user can use man:chpass[1] to change their default shell and personal information associated with their user account.
The superuser can use this utility to change additional account information for any user.

When passed no options, aside from an optional username, man:chpass[1] displays an editor containing user information.
When the user exits from the editor, the user database is updated with the new information.

[NOTE]
====
This utility will prompt for the user's password when exiting the editor, unless the utility is run as the superuser.
====

In <<users-modifying-chpass-su>>, the superuser has typed `chpass jru` and is now viewing the fields that can be changed for this user.
If `jru` runs this command instead, only the last six fields will be displayed and available for editing.
This is shown in <<users-modifying-chpass-ru>>.

[[users-modifying-chpass-su]]
.Using `chpass` as Superuser
[example]
====
[source,shell]
....
#Changing user database information for jru.
Login: jru
Password: *
Uid [#]: 1001
Gid [# or name]: 1001
Change [month day year]:
Expire [month day year]:
Class:
Home directory: /home/jru
Shell: /usr/local/bin/zsh
Full Name: J. Random User
Office Location:
Office Phone:
Home Phone:
Other information:
....
====

[[users-modifying-chpass-ru]]
.Using `chpass` as Regular User
[example]
====
[source,shell]
....
#Changing user database information for jru.
Shell: /usr/local/bin/zsh
Full Name: J. Random User
Office Location:
Office Phone:
Home Phone:
Other information:
....
====

[NOTE]
====
The commands man:chfn[1] and man:chsh[1] are links to man:chpass[1], as are man:ypchpass[1], man:ypchfn[1], and man:ypchsh[1].
Since NIS support is automatic, specifying the `yp` before the command is not necessary.
How to configure NIS is covered in crossref:network-servers[network-servers,Network Servers].
====

[[users-passwd]]
==== Change user password

Any user can easily change their password using man:passwd[1].
To prevent accidental or unauthorized changes, this command will prompt for the user's original password before a new password can be set:

.Changing Your Password
[example]
====
[source,shell]
....
% passwd
Changing local password for jru.
Old password:
New password:
Retype new password:
passwd: updating the database...
passwd: done
....
====

The superuser can change any user's password by specifying the username when running man:passwd[1].
When this utility is run as the superuser, it will not prompt for the user's current password.
This allows the password to be changed when a user cannot remember the original password.

.Changing Another User's Password as the Superuser
[example]
====
[source,shell]
....
# passwd jru
Changing local password for jru.
New password:
Retype new password:
passwd: updating the database...
passwd: done
....
====

[NOTE]
====
As with man:chpass[1], man:yppasswd[1] is a link to man:passwd[1], so NIS works with either command.
====

[[users-pw]]
==== Create, remove, modify and display system users and groups

The man:pw[8] utility can create, remove, modify, and display users and groups.
It functions as a front end to the system user and group files.
man:pw[8] has a very powerful set of command line options that make it suitable for use in shell scripts, but new users may find it more complicated than the other commands presented in this section.

[[users-groups]]
=== Managing Groups

A group is a list of users. A group is identified by its group name and GID.
In FreeBSD, the kernel uses the UID of a process, and the list of groups it belongs to, to determine what the process is allowed to do.
Most of the time, the GID of a user or process usually means the first group in the list.

The group name to GID mapping is listed in `/etc/group`.
This is a plain text file with four colon-delimited fields.
The first field is the group name, the second is the encrypted password, the third the GID, and the fourth the comma-delimited list of members.
For a more complete description of the syntax, refer to man:group[5].

The superuser can modify `/etc/group` using a text editor, although editing the group file using man:vigr[8] is preferred because it can catch some common mistakes.
Alternatively, man:pw[8] can be used to add and edit groups.
For example, to add a group called `teamtwo` and then confirm that it exists:

[WARNING]
====
Care must be taken when using the operator group, as unintended superuser-like access privileges may be granted, including but not limited to shutdown, reboot, and access to all items in `/dev` in the group.
====

.Adding a Group Using man:pw[8]
[example]
====
[source,shell]
....
# pw groupadd teamtwo
# pw groupshow teamtwo
teamtwo:*:1100:
....
====

In this example, `1100` is the GID of `teamtwo`.
Right now, `teamtwo` has no members.
This command will add `jru` as a member of `teamtwo`.

.Adding User Accounts to a New Group Using man:pw[8]
[example]
====
[source,shell]
....
# pw groupmod teamtwo -M jru
# pw groupshow teamtwo
teamtwo:*:1100:jru
....
====

The argument to `-M` is a comma-delimited list of users to be added to a new (empty) group or to replace the members of an existing group.
To the user, this group membership is different from (and in addition to) the user's primary group listed in the password file.
This means that the user will not show up as a member when using `groupshow` with man:pw[8], but will show up when the information is queried via man:id[1] or a similar tool.
When man:pw[8] is used to add a user to a group, it only manipulates `/etc/group` and does not attempt to read additional data from `/etc/passwd`.

.Adding a New Member to a Group Using man:pw[8]
[example]
====
[source,shell]
....
# pw groupmod teamtwo -m db
# pw groupshow teamtwo
teamtwo:*:1100:jru,db
....
====

In this example, the argument to `-m` is a comma-delimited list of users who are to be added to the group.
Unlike the previous example, these users are appended to the group and do not replace existing users in the group.

.Using man:id[1] to Determine Group Membership
[example]
====
[source,shell]
....
% id jru
uid=1001(jru) gid=1001(jru) groups=1001(jru), 1100(teamtwo)
....
====

In this example, `jru` is a member of the groups `jru` and `teamtwo`.

For more information about this command and the format of `/etc/group`, refer to man:pw[8] and man:group[5].

[[permissions]]
== Permissions

In FreeBSD, every file and directory has an associated set of permissions and several utilities are available for viewing and modifying these permissions. 
Understanding how permissions work is necessary to make sure that users are able to access the files that they need and are unable to improperly access the files used by the operating system or owned by other users.

This section discusses the traditional UNIX(R) permissions used in FreeBSD.
For finer-grained file system access control, refer to crossref:security[fs-acl,Access Control Lists].

In UNIX(R), basic permissions are assigned using three types of access: read, write, and execute.
These access types are used to determine file access to the file's owner, group, and others (everyone else).
The read, write, and execute permissions can be represented as the letters `r`, `w`, and `x`.
They can also be represented as binary numbers as each permission is either on or off (`0`).
When represented as a number, the order is always read as `rwx`, where `r` has an on value of `4`, `w` has an on value of `2` and `x` has an on value of `1`.

Table 4.1 summarizes the possible numeric and alphabetic possibilities.
When reading the "Directory Listing" column, a `-` is used to represent a permission that is set to off.

.UNIX(R) Permissions
[cols="1,1,1", frame="none", options="header"]
|===
| Value
| Permission
| Directory Listing

|0
|No read, no write, no execute
|`---`

|1
|No read, no write, execute
|`--x`

|2
|No read, write, no execute
|`-w-`

|3
|No read, write, execute
|`-wx`

|4
|Read, no write, no execute
|`r--`

|5
|Read, no write, execute
|`r-x`

|6
|Read, write, no execute
|`rw-`

|7
|Read, write, execute
|`rwx`
|===

Use the `-l` argument with man:ls[1] to view a long directory listing that includes a column of information about a file's permissions for the owner, group, and everyone else.
For example, `ls -l` in an arbitrary directory may show:

[source,shell]
....
% ls -l
total 530
-rw-r--r--  1 root  wheel     512 Sep  5 12:31 myfile
-rw-r--r--  1 root  wheel     512 Sep  5 12:31 otherfile
-rw-r--r--  1 root  wheel    7680 Sep  5 12:31 email.txt
....

Focusing on the line for `myfile`, the first `(leftmost)` character indicates whether this file is a regular file, a directory, a special character device, a socket, or any other special pseudo-file device.
In this example, the `-` indicates a regular file.
The next three characters, `rw-` in this example, give the permissions for the owner of the file.
The next three characters, `r--`, give the permissions for the group that the file belongs to.
The final three characters, `r--`, give the permissions for the rest of the world.
A dash means that the permission is turned off.
In this example, the permissions are set so the owner can read and write to the file, the group can read the file, and the rest of the world can only read the file.
According to the table above, the permissions for this file would be `644`, where each digit represents the three parts of the file's permission.

How does the system control permissions on devices? FreeBSD treats most hardware devices as a file that programs can open, read, and write data to. 
These special device files are stored in `/dev/`.

Directories are also treated as files.
They have read, write, and execute permissions.
The executable bit for a directory has a slightly different meaning than that of files.
When a directory is marked executable, it means it is possible to change into that directory using man:cd[1].
This also means that it is possible to access the files within that directory, subject to the permissions on the files themselves.

In order to perform a directory listing, the read permission must be set on the directory.
In order to delete a file that one knows the name of, it is necessary to have write _and_ execute permissions to the directory containing the file.

There are more permission bits, but they are primarily used in special circumstances such as setuid binaries and sticky directories.
For more information on file permissions and how to set them, refer to man:chmod[1].

=== Symbolic Permissions

Symbolic permissions use characters instead of octal values to assign permissions to files or directories.
Symbolic permissions use the syntax of (who) (action) (permissions), where the following values are available:

[.informaltable]
[cols="1,1,1", frame="none", options="header"]
|===
| Option
| Letter
| Represents

|(who)
|u
|User

|(who)
|g
|Group owner

|(who)
|o
|Other

|(who)
|a
|All ("world")

|(action)
|+
|Adding permissions

|(action)
|-
|Removing permissions

|(action)
|=
|Explicitly set permissions

|(permissions)
|r
|Read

|(permissions)
|w
|Write

|(permissions)
|x
|Execute

|(permissions)
|t
|Sticky bit

|(permissions)
|s
|Set UID or GID
|===

These values are used with man:chmod[1], but with letters instead of numbers.
For example, the following command would block both members of the group associated with _FILE_ and all other users from accessing _FILE_:

[source,shell]
....
% chmod go= FILE
....

A comma separated list can be provided when more than one set of changes to a file must be made.
For example, the following command removes the group and "world" write permission on _FILE_, and adds the execute permissions for everyone:

[source,shell]
....
% chmod go-w,a+x FILE
....

=== FreeBSD File Flags

In addition to file permissions, FreeBSD supports the use of "file flags".
These flags add an additional level of security and control over files, but not directories.
With file flags, even `root` can be prevented from removing or altering files.

File flags are modified using man:chflags[1].
For example, to enable the system undeletable flag on the file `file1`, issue the following command:

[source,shell]
....
# chflags sunlink file1
....

To disable the system undeletable flag, put a "no" in front of the `sunlink`:

[source,shell]
....
# chflags nosunlink file1
....

To view the flags of a file, use `-lo` with man:ls[1]:

[source,shell]
....
# ls -lo file1
....

[.programlisting]
....
-rw-r--r--  1 trhodes  trhodes  sunlnk 0 Mar  1 05:54 file1
....

Several file flags may only be added or removed by the `root` user.
In other cases, the file owner may set its file flags.
Refer to man:chflags[1] and man:chflags[2] for more information.

=== The setuid, setgid, and sticky Permissions

Other than the permissions already discussed, there are three other specific settings that all administrators should know about.
They are the `setuid`, `setgid`, and `sticky` permissions.

These settings are important for some UNIX(R) operations as they provide functionality not normally granted to normal users.
To understand them, the difference between the real user ID and effective user ID must be noted.

The real user ID is the UID who owns or starts the process.
The effective UID is the user ID the process runs as.
As an example, man:passwd[1] runs with the real user ID when a user changes their password.
However, in order to update the password database, the command runs as the effective ID of the `root` user.
This allows users to change their passwords without seeing a `Permission Denied` error.

The setuid permission may be added symbolically by adding the `s` permission for the user as in the following example:
 
[source,shell]
....
# chmod u+s suidexample.sh
....

The setuid permission may also be set by prefixing a permission set with the number four (4) as shown in the following example:

[source,shell]
....
# chmod 4755 suidexample.sh
....

The permissions on `suidexample.sh` now look like the following:

[.programlisting]
....
-rwsr-xr-x   1 trhodes  trhodes    63 Aug 29 06:36 suidexample.sh
....

Note that a `s` is now part of the permission set designated for the file owner, replacing the executable bit.
This allows utilities which need elevated permissions, such as man:passwd[1].

[NOTE]
====
The `nosuid` man:mount[8] option will cause such binaries to silently fail without alerting the user.
That option is not completely reliable as a `nosuid` wrapper may be able to circumvent it.
====

To view this in real time, open two terminals.
On one, type `passwd` as a normal user.
While it waits for a new password, check the process table and look at the user information for man:passwd[1]:

In terminal A:

[source,shell]
....
Changing local password for trhodes
Old Password:
....

In terminal B:

[source,shell]
....
# ps aux | grep passwd
....

[source,shell]
....
trhodes  5232  0.0  0.2  3420  1608   0  R+    2:10AM   0:00.00 grep passwd
root     5211  0.0  0.2  3620  1724   2  I+    2:09AM   0:00.01 passwd
....

Although man:passwd[1] is run as a normal user, it is using the effective UID of `root`.

The `setgid` permission performs the same function as the `setuid` permission; except that it alters the group settings.
When an application or utility executes with this setting, it will be granted the permissions based on the group that owns the file, not the user who started the process.

To set the `setgid` permission on a file symbolically, add the `s` permission for the group with man:chmod[1]:

[source,shell]
....
# chmod g+s sgidexample.sh
....
 
Alternatively, provide man:chmod[1] with a leading two (2):

[source,shell]
....
# chmod 2755 sgidexample.sh
....

In the following listing, notice that the `s` is now in the field designated for the group permission settings:

[source,shell]
....
-rwxr-sr-x   1 trhodes  trhodes    44 Aug 31 01:49 sgidexample.sh
....

[NOTE]
====
In these examples, even though the shell script in question is an executable file, it will not run with a different EUID or effective user ID.
This is because shell scripts may not access the man:setuid[2] system calls.
====

The `setuid` and `setgid` permission bits may lower system security, by allowing for elevated permissions.
The third special permission, the `sticky bit`, can strengthen the security of a system.

When the `sticky bit` is set on a directory, it allows file deletion only by the file owner.
This is useful to prevent file deletion in public directories, such as `/tmp`, by users who do not own the file.
To utilize this permission, add the `t` mode to the file:

[source,shell]
....
# chmod +t /tmp
....

Alternatively, prefix the permission set with a one (1):

[source,shell]
....
# chmod 1777 /tmp
....

The `sticky bit` permission will display as a `t` at the very end of the permission set:

[source,shell]
....
# ls -al / | grep tmp
....

[source,shell]
....
drwxrwxrwt  10 root  wheel         512 Aug 31 01:49 tmp
....

[[dirstructure]]
== Directory Structure

The FreeBSD directory hierarchy is fundamental to obtaining an overall understanding of the system.
The most important directory is root or, "/".
This directory is the first one mounted at boot time and it contains the base system necessary to prepare the operating system for multi-user operation. 
The root directory also contains mount points for other file systems that are mounted during the transition to multi-user operation.

A mount point is a directory where additional file systems can be grafted onto a parent file system (usually the root file system).
This is further described in <<disk-organization>>.
Standard mount points include `/usr/`, `/var/`, `/tmp/`, `/mnt/`, and `/cdrom/`.
These directories are usually referenced to entries in `/etc/fstab`.
This file is a table of various file systems and mount points and is read by the system.
Most of the file systems in `/etc/fstab` are mounted automatically at boot time from the script man:rc[8] unless their entry includes `noauto`. 
Details can be found in <<disks-fstab>>.

A complete description of the file system hierarchy is available in man:hier[7].
The following table provides a brief overview of the most common directories.

[cols="25h,~"]
|===
| Directory
| Description

|`/`
|Root directory of the file system.

|`/bin/`
|User utilities fundamental to both single-user and multi-user environments.

|`/boot/`
|Programs and configuration files used during operating system bootstrap.

|`/boot/defaults/`
|Default boot configuration files. Refer to man:loader.conf[5] for details.

|`/dev/`
|Device special files managed by man:devfs[5]

|`/etc/`
|System configuration files and scripts.

|`/etc/defaults/`
|Default system configuration files. Refer to man:rc[8] for details.

|`/etc/periodic/`
|Scripts that run daily, weekly, and monthly, via man:cron[8]. Refer to man:periodic[8] for details.

|`/lib/`
|Critical system libraries needed for binaries in `/bin` and `/sbin`

|`/libexec/`
|Critical system files

|`/media/`
|Contains subdirectories to be used as mount points for removable media such as CDs, USB drives, and floppy disks

|`/mnt/`
|Empty directory commonly used by system administrators as a temporary mount point.

|`/net/`
|Automounted NFS shares; see man:auto_master[5]

|`/proc/`
|Process file system. Refer to man:procfs[5], man:mount_procfs[8] for details.

|`/rescue/`
|Statically linked programs for emergency recovery as described in man:rescue[8].

|`/root/`
|Home directory for the `root` account.

|`/sbin/`
|System programs and administration utilities fundamental to both single-user and multi-user environments.

|`/tmp/`
|Temporary files which are usually _not_ preserved across a system reboot. A memory-based file system is often mounted at `/tmp`. This can be automated using the tmpmfs-related variables of man:rc.conf[5] or with an entry in `/etc/fstab`; refer to man:mdmfs[8] for details.

|`/usr/`
|The majority of user utilities and applications.

|`/usr/bin/`
|Common utilities, programming tools, and applications.

|`/usr/include/`
|Standard C include files.

|`/usr/lib/`
|Archive libraries.

|`/usr/libdata/`
|Miscellaneous utility data files.

|`/usr/libexec/`
|System daemons and system utilities executed by other programs.

|`/usr/local/`
|Local executables and libraries. Also used as the default destination for the FreeBSD ports framework. Within `/usr/local`, the general layout sketched out by man:hier[7] for `/usr` should be used. Exceptions are the man directory, which is directly under `/usr/local` rather than under `/usr/local/share`, and the ports documentation is in `share/doc/port`.

|`/usr/ports/`
|The FreeBSD Ports Collection (optional).

|`/usr/sbin/`
|System daemons and system utilities executed by users.

|`/usr/share/`
|Architecture-independent files.

|`/usr/src/`
|BSD and/or local source files.

|`/var/`
|Multi-purpose log, temporary, transient, and spool files.

|`/var/log/`
|Miscellaneous system log files.

|`/var/tmp/`
|Temporary files which are usually preserved across a system reboot.

|===

[[disk-organization]]
== Disk Organization

The smallest unit of organization that FreeBSD uses to find files is the filename.
Filenames are case-sensitive, which means that `readme.txt` and `README.TXT` are two separate files.
FreeBSD does not use the extension of a file to determine whether the file is a program, document, or some other form of data.

Files are stored in directories.
A directory may contain no files, or it may contain many hundreds of files.
A directory can also contain other directories, allowing a hierarchy of directories within one another in order to organize data.

Files and directories are referenced by giving the file or directory name, followed by a forward slash, `/`, followed by any other directory names that are necessary.
For example, if the directory `foo` contains a directory `bar` which contains the file `readme.txt`, the full name, or _path_, to the file is `foo/bar/readme.txt`.
Note that this is different from Windows(R) which uses `\` to separate file and directory names.
FreeBSD does not use drive letters, or other drive names in the path.
For example, one would not type `c:\foo\bar\readme.txt` on FreeBSD.

Directories and files are stored in a file system.
Each file system contains exactly one directory at the very top level, called the _root directory_ for that file system.
This root directory can contain other directories.
One file system is designated the _root file system_ or `/`.
Every other file system is _mounted_ under the root file system.
No matter how many disks are on the FreeBSD system, every directory appears to be part of the same disk.

Consider three file systems, called `A`, `B`, and `C`.
Each file system has one root directory, which contains two other directories, called `A1`, `A2` (and likewise `B1`, `B2` and `C1`, `C2`).

Call `A` the root file system.
If man:ls[1] is used to view the contents of this directory, it will show two subdirectories, `A1` and `A2`.
The directory tree looks like this:

image::example-dir1.png[Directory tree with the root directory and two subdirectories, A1 and A2]

A file system must be mounted on to a directory in another file system.
When mounting file system `B` on to the directory `A1`, the root directory of `B` replaces `A1`, and the directories in `B` appear accordingly:

image::example-dir2.png[Directory tree with the root directory and two subdirectories, A1 and A2. And more subdirectories, B1 and B2 hanging from A1]

Any files that are in the `B1` or `B2` directories can be reached with the path `/A1/B1` or `/A1/B2` as necessary.
Any files that were in `/A1` have been temporarily hidden.
They will reappear if `B` is _unmounted_ from `A`.

If `B` had been mounted on `A2` then the diagram would look like this:

image::example-dir3.png[Directory tree with the root directory and two subdirectories, A1 and A2. And more subdirectories, B1 and B2 hanging from A2]

and the paths would be `/A2/B1` and `/A2/B2` respectively.

File systems can be mounted on top of one another.
Continuing the last example, the `C` file system could be mounted on top of the `B1` directory in the `B` file system, leading to this arrangement:

image::example-dir4.png[A complex directory tree. With different subdirectories hanging from root.]

Or `C` could be mounted directly on to the `A` file system, under the `A1` directory:

image::example-dir5.png[A complex directory tree. With different subdirectories hanging from root.]

It is entirely possible to have one large root file system, and not need to create any others.
There are some drawbacks to this approach, and one advantage.

.Benefits of Multiple File Systems
* Different file systems can have different _mount options_. For example, the root file system can be mounted read-only, making it impossible for users to inadvertently delete or edit a critical file. Separating user-writable file systems, such as `/home`, from other file systems allows them to be mounted _nosuid_. This option prevents the _suid_/_guid_ bits on executables stored on the file system from taking effect, possibly improving security.
* FreeBSD automatically optimizes the layout of files on a file system, depending on how the file system is being used. So a file system that contains many small files that are written frequently will have a different optimization to one that contains fewer, larger files. By having one big file system this optimization breaks down.
* FreeBSD's file systems are robust if power is lost. However, a power loss at a critical point could still damage the structure of the file system. By splitting data over multiple file systems it is more likely that the system will still come up, making it easier to restore from backup as necessary.

.Benefit of a Single File System
* File systems are a fixed size. If you create a file system when you install FreeBSD and give it a specific size, you may later discover that you need to make the partition bigger. This is not easily accomplished without backing up, recreating the file system with the new size, and then restoring the backed up data.
+
[IMPORTANT]
====
FreeBSD features the man:growfs[8] command, which makes it possible to increase the size of file system on the fly, removing this limitation.
A file system can only be expanded into free space in the partition in which it resides.
If there is space after the partition, the partition can be expanded with man:gpart[8].
If the partition is the last one on a virtual disk, and the disk is expanded, the partition can then be expanded.
====

File systems are contained in partitions.
This does not have the same meaning as the common usage of the term partition (for example, MS-DOS(R) partition), because of FreeBSD's UNIX(R) heritage.
Each partition is identified by a letter from `a` through to `h`.
Each partition can contain only one file system, which means that file systems are often described by either their typical mount point in the file system hierarchy, or the letter of the partition they are contained in.

FreeBSD also uses disk space for _swap space_ to provide _virtual memory_.
This allows your computer to behave as though it has much more memory than it actually does.
When FreeBSD runs out of memory, it moves some of the data that is not currently being used to the swap space, and moves it back in (moving something else out) when it needs it.

Some partitions have certain conventions associated with them.

[cols="25h,~"]
|===
| Partition
| Convention

|`a`
|Normally contains the root file system.

|`b`
|Normally contains swap space.

|`c`
|Normally the same size as the enclosing slice. This allows utilities that need to work on the entire slice, such as a bad block scanner, to work on the `c` partition. A file system would not normally be created on this partition.

|`d`
|Partition `d` used to have a special meaning associated with it, although that is now gone and `d` may work as any normal partition.
|===

Disks in FreeBSD are divided into slices, referred to in Windows(R) as partitions, which are numbered from 1 to 4.
These are then divided into partitions, which contain file systems, and are labeled using letters.

Slice numbers follow the device name, prefixed with an `s`, starting at 1.
So "da0__s1__" is the first slice on the first SCSI drive.
There can only be four physical slices on a disk, but there can be logical slices inside physical slices of the appropriate type.
These extended slices are numbered starting at 5, so "ada0__s5__" is the first extended slice on the first SATA disk.
These devices are used by file systems that expect to occupy a slice.

Slices, "dangerously dedicated" physical drives, and other drives contain _partitions_, which are represented as letters from `a` to `h`.
This letter is appended to the device name, so "da0__a__" is the `a` partition on the first `da` drive, which is "dangerously dedicated".
"ada1s3__e__" is the fifth partition in the third slice of the second SATA disk drive.

Finally, each disk on the system is identified.
A disk name starts with a code that indicates the type of disk, and then a number, indicating which disk it is.
Unlike slices, disk numbering starts at 0.
Common codes are listed in <<disks-naming>>.

When referring to a partition, include the disk name, `s`, the slice number, and then the partition letter.
Examples are shown in <<basics-disk-slice-part>>.

<<basics-concept-disk-model>> shows a conceptual model of a disk layout.

When installing FreeBSD, configure the disk slices, create partitions within the slice to be used for FreeBSD, create a file system or swap space in each partition, and decide where each file system will be mounted.

[[disks-naming]]
.Disk Device Names
[cols="1,1", frame="none", options="header"]
|===
| Drive Type
| Drive Device Name

|SATA and IDE hard drives
|`ada`

|SCSI hard drives and USB storage devices
|`da`

|NVMe storage
|`nvd` or `nda`

|SATA and IDE CD-ROM drives
|`cd`

|SCSICD-ROM drives
|`cd`

|Floppy drives
|`fd`

|SCSI tape drives
|`sa`

|RAID drives
|Examples include `aacd` for Adaptec(R) AdvancedRAID, `mlxd` and `mlyd` for Mylex(R), `amrd` for AMI MegaRAID(R), `idad` for Compaq Smart RAID, `twed` for 3ware(R) RAID.
|===

[example]
====
[[basics-disk-slice-part]]
.Sample Disk, Slice, and Partition Names
[.informaltable]
[cols="1,1", frame="none", options="header"]
|===
| Name
| Meaning

|`ada0s1a`
|The first partition (`a`) on the first slice (`s1`) on the first SATA disk (`ada0`).

|`da1s2e`
|The fifth partition (`e`) on the second slice (`s2`) on the second SCSI disk (`da1`).
|===
====

[[basics-concept-disk-model]]
.Conceptual Model of a Disk
[example]
====
This diagram shows FreeBSD's view of the first SATA disk attached to the system.
Assume that the disk is 250 GB in size, and contains an 80 GB slice and a 170 GB slice (MS-DOS(R) partitions).
The first slice contains a Windows(R) NTFS file system, `C:`, and the second slice contains a FreeBSD installation.
This example FreeBSD installation has four data partitions and a swap partition.

The four partitions each hold a file system.
Partition `a` is used for the root file system, `d` for `/var/`, `e` for `/tmp/`, and `f` for `/usr/`.
Partition letter `c` refers to the entire slice, and so is not used for ordinary partitions.

image::disk-layout.png[Layout of a shared drive between Windows and FreeBSD]
====

[[mount-unmount]]
== Mounting and Unmounting File Systems

The file system is best visualized as a tree, rooted, as it were, at `/`. `/dev`, `/usr`, and the other directories in the root directory are branches, which may have their own branches, such as `/usr/local`, and so on.

There are various reasons to house some of these directories on separate file systems.
`/var` contains the directories `log/`, `spool/`, and various types of temporary files, and as such, may get filled up. 
Filling up the root file system is not a good idea, so splitting `/var` from `/` is often favorable.

Another common reason to contain certain directory trees on other file systems is if they are to be housed on separate physical disks, or are separate virtual disks, such as Network File System mounts, described in crossref:network-servers[network-nfs,“Network File System (NFS)”], or CDROM drives.

[[disks-fstab]]
=== The fstab File

During the boot process (crossref:boot[boot,The FreeBSD Booting Process]), file systems listed in `/etc/fstab` are automatically mounted except for the entries containing `noauto`.
This file contains entries in the following format:

[.programlisting]
....
device       /mount-point fstype     options      dumpfreq     passno
....

`device`::
An existing device name as explained in <<disks-naming>>.

`mount-point`::
An existing directory on which to mount the file system.

`fstype`::
The file system type to pass to man:mount[8].
The default FreeBSD file system is `ufs`.

`options`::
Either `rw` for read-write file systems, or `ro` for read-only file systems, followed by any other options that may be needed.
A common option is `noauto` for file systems not normally mounted during the boot sequence.
Other options are listed in man:mount[8].

`dumpfreq`::
Used by man:dump[8] to determine which file systems require dumping.
If the field is missing, a value of zero is assumed.

`passno`::
Determines the order in which UFS file systems should be checked by man:fsck[8] after a reboot.
File systems that should be skipped should have their `passno` set to zero.
The root file system needs to be checked before everything else and should have its `passno` set to one.
The other file systems should be set to values greater than one.
If more than one file system has the same `passno`, man:fsck[8] will attempt to check file systems in parallel if possible.

Refer to man:fstab[5] for more information on the format of `/etc/fstab` and its options.

[[disks-mount]]
=== Using man:mount[8]

File systems are mounted using man:mount[8].
The most basic syntax is as follows:

[example]
====
[source,shell]
....
# mount device mountpoint
....
====

This command provides many options which are described in man:mount[8], The most commonly used options include:

.Mount Options
`-a`::
Mount all the file systems listed in `/etc/fstab`, except those marked as "noauto", excluded by the `-t` flag, or those that are already mounted.

`-d`::
Do everything except for the actual mount system call.
This option is useful in conjunction with the `-v` flag to determine what man:mount[8] is actually trying to do.

`-f`::
Force the mount of an unclean file system (dangerous), or the revocation of write access when downgrading a file system's mount status from read-write to read-only.

`-r`::
Mount the file system read-only.
This is identical to using `-o ro`.

``-t _fstype_``::
Mount the specified file system type or mount only file systems of the given type, if `-a` is included.
"ufs" is the default file system type.

`-u`::
Update mount options on the file system.

`-v`::
Be verbose.

`-w`::
Mount the file system read-write.

The following options can be passed to `-o` as a comma-separated list:

nosuid::
Do not interpret setuid or setgid flags on the file system.
This is also a useful security option.

[[disks-umount]]
=== Using man:umount[8]

To unmount a file system use man:umount[8].
This command takes one parameter which can be a mountpoint, device name, `-a` or `-A`.

All forms take `-f` to force unmounting, and `-v` for verbosity.
Be warned that `-f` is not generally a good idea as it might crash the computer or damage data on the file system.

To unmount all mounted file systems, or just the file system types listed after `-t`, use `-a` or `-A`.
Note that `-A` does not attempt to unmount the root file system.

[[basics-processes]]
== Processes and Daemons

FreeBSD is a multi-tasking operating system.
Each program running at any one time is called a _process_.
Every running command starts at least one new process and there are a number of system processes that are run by FreeBSD.

Each process is uniquely identified by a number called a _process ID_ (PID).
Similar to files, each process has one owner and group, and the owner and group permissions are used to determine which files and devices the process can open.
Most processes also have a parent process that started them.
For example, the shell is a process, and any command started in the shell is a process which has the shell as its parent process.
The exception is a special process called man:init[8] which is always the first process to start at boot time and which always has a PID of `1`.

Some programs are not designed to be run with continuous user input and disconnect from the terminal at the first opportunity.
For example, a web server responds to web requests, rather than user input.
Mail servers are another example of this type of application.
These types of programs are known as _daemons_.
The term daemon comes from Greek mythology and represents an entity that is neither good nor evil, and which invisibly performs useful tasks.
This is why the BSD mascot is the cheerful-looking daemon with sneakers and a pitchfork.

There is a convention to name programs that normally run as daemons with a trailing "d".
For example, BIND is the Berkeley Internet Name Domain, but the actual program that executes is `named`.
The Apache web server program is `httpd` and the line printer spooling daemon is `lpd`.
This is only a naming convention.
For example, the main mail daemon for the Sendmail application is `sendmail`, and not `maild`.

=== Viewing Processes

To see the processes running on the system, use man:ps[1] or man:top[1].
To display a static list of the currently running processes, their PIDs, how much memory they are using, and the command they were started with, use man:ps[1].
To display all the running processes and update the display every few seconds in order to interactively see what the computer is doing, use man:top[1].

By default, man:ps[1] only shows the commands that are running and owned by the user.
For example:

[source,shell]
....
% ps
 PID TT  STAT    TIME COMMAND
8203  0  Ss   0:00.59 /bin/csh
8895  0  R+   0:00.00 ps
....

The output from man:ps[1] is organized into a number of columns.
The `PID` column displays the process ID.
PIDs are assigned starting at 1, go up to 99999, then wrap around back to the beginning.
However, a PID is not reassigned if it is already in use.
The `TT` column shows the tty the program is running on and `STAT` shows the program's state.
`TIME` is the amount of time the program has been running on the CPU.
This is usually not the elapsed time since the program was started, as most programs spend a lot of time waiting for things to happen before they need to spend time on the CPU.
Finally, `COMMAND` is the command that was used to start the program.

A number of different options are available to change the information that is displayed.
One of the most useful sets is `auxww`, where `a` displays information about all the running processes of all users, `u` displays the username and memory usage of the process' owner, `x` displays information about daemon processes, and `ww` causes man:ps[1] to display the full command line for each process, rather than truncating it once it gets too long to fit on the screen.

The output from man:top[1] is similar:

[source,shell]
....
% top
last pid:  9609;  load averages:  0.56,  0.45,  0.36              up 0+00:20:03  10:21:46
107 processes: 2 running, 104 sleeping, 1 zombie
CPU:  6.2% user,  0.1% nice,  8.2% system,  0.4% interrupt, 85.1% idle
Mem: 541M Active, 450M Inact, 1333M Wired, 4064K Cache, 1498M Free
ARC: 992M Total, 377M MFU, 589M MRU, 250K Anon, 5280K Header, 21M Other
Swap: 2048M Total, 2048M Free

  PID USERNAME    THR PRI NICE   SIZE    RES STATE   C   TIME   WCPU COMMAND
  557 root          1 -21  r31   136M 42296K select  0   2:20  9.96% Xorg
 8198 dru           2  52    0   449M 82736K select  3   0:08  5.96% kdeinit4
 8311 dru          27  30    0  1150M   187M uwait   1   1:37  0.98% firefox
  431 root          1  20    0 14268K  1728K select  0   0:06  0.98% moused
 9551 dru           1  21    0 16600K  2660K CPU3    3   0:01  0.98% top
 2357 dru           4  37    0   718M   141M select  0   0:21  0.00% kdeinit4
 8705 dru           4  35    0   480M    98M select  2   0:20  0.00% kdeinit4
 8076 dru           6  20    0   552M   113M uwait   0   0:12  0.00% soffice.bin
 2623 root          1  30   10 12088K  1636K select  3   0:09  0.00% powerd
 2338 dru           1  20    0   440M 84532K select  1   0:06  0.00% kwin
 1427 dru           5  22    0   605M 86412K select  1   0:05  0.00% kdeinit4
....

The output is split into two sections.
The header (the first five or six lines) shows the PID of the last process to run, the system load averages (which are a measure of how busy the system is), the system uptime (time since the last reboot) and the current time.
The other figures in the header relate to how many processes are running, how much memory and swap space has been used, and how much time the system is spending in different CPU states.
If the ZFS file system module has been loaded, an `ARC` line indicates how much data was read from the memory cache instead of from disk.

Below the header is a series of columns containing similar information to the output from man:ps[1], such as the PID, username, amount of CPU time, and the command that started the process.
By default, man:top[1] also displays the amount of memory space taken by the process.
This is split into two columns: one for total size and one for resident size.
Total size is how much memory the application has needed and the resident size is how much it is actually using now.

man:top[1] automatically updates the display every two seconds.
A different interval can be specified with `-s`.

[[basics-daemons]]
=== Killing Processes

One way to communicate with any running process or daemon is to send a _signal_ using man:kill[1].
There are a number of different signals; some have a specific meaning while others are described in the application's documentation.
A user can only send a signal to a process they own and sending a signal to someone else's process will result in a permission denied error.
The exception is the `root` user, who can send signals to anyone's processes.

The operating system can also send a signal to a process.
If an application is badly written and tries to access memory that it is not supposed to, FreeBSD will send the process the "Segmentation Violation" signal (`SIGSEGV`).
If an application has been written to use the man:alarm[3] system call to be alerted after a period of time has elapsed, it will be sent the "Alarm" signal (`SIGALRM`).

Two signals can be used to stop a process: `SIGTERM` and `SIGKILL`.
`SIGTERM` is the polite way to kill a process as the process can read the signal, close any log files it may have open, and attempt to finish what it is doing before shutting down.
In some cases, a process may ignore `SIGTERM` if it is in the middle of some task that cannot be interrupted.

`SIGKILL` cannot be ignored by a process.
Sending a `SIGKILL` to a process will usually stop that process there and then. footnote:[There are a few tasks that cannot be interrupted. For example, if the process is trying to read from a file that is on another computer on the network, and the other computer is unavailable, the process is said to be uninterruptible. Eventually the process will time out, typically after two minutes. As soon as this time out occurs the process will be killed.].

Other commonly used signals are `SIGHUP`, `SIGUSR1`, and `SIGUSR2`.
Since these are general purpose signals, different applications will respond differently.

For example, after changing a web server's configuration file, the web server needs to be told to re-read its configuration.
Restarting `httpd` would result in a brief outage period on the web server.
Instead, send the daemon the `SIGHUP` signal.
Be aware that different daemons will have different behavior, so refer to the documentation for the daemon to determine if `SIGHUP` will achieve the desired results.

[IMPORTANT]
====
Killing a random process on the system is a bad idea.
In particular, man:init[8], PID 1, is special.
Running `/bin/kill -s KILL 1` is a quick, and unrecommended, way to shutdown the system.
_Always_ double check the arguments to man:kill[1] _before_ pressing kbd:[Return].
====

[[shells]]
== Shells

A _shell_ provides a command line interface for interacting with the operating system.
A shell receives commands from the input channel and executes them.
Many shells provide built in functions to help with everyday tasks such as file management, file globbing, command line editing, command macros, and environment variables.
FreeBSD comes with several shells, including the Bourne shell (man:sh[1]) and the extended C shell (man:tcsh[1]).
Other shells are available from the FreeBSD Ports Collection, such as `zsh` and `bash`.

The shell that is used is really a matter of taste.
A C programmer might feel more comfortable with a C-like shell such as man:tcsh[1].
A Linux(R) user might prefer `bash`.
Each shell has unique properties that may or may not work with a user's preferred working environment, which is why there is a choice of which shell to use.

One common shell feature is filename completion.
After a user types the first few letters of a command or filename and presses kbd:[Tab], the shell completes the rest of the command or filename. 
Consider two files called `foobar` and `football`.
To delete `foobar`, the user might type `rm foo` and press kbd:[Tab] to complete the filename.

But the shell only shows `rm foo`.
It was unable to complete the filename because both `foobar` and `football` start with `foo`.
Some shells sound a beep or show all the choices if more than one name matches.
The user must then type more characters to identify the desired filename.
Typing a `t` and pressing kbd:[Tab] again is enough to let the shell determine which filename is desired and fill in the rest.

Another feature of the shell is the use of environment variables.
Environment variables are a variable/key pair stored in the shell's environment.
This environment can be read by any program invoked by the shell, and thus contains a lot of program configuration.
<<shell-env-vars>> provides a list of common environment variables and their meanings.
Note that the names of environment variables are always in uppercase.

[[shell-env-vars]]
.Common Environment Variables
[cols="25h,~"]
|===
| Variable
| Description

|`USER`
|Current logged in user's name.

|`PATH`
|Colon-separated list of directories to search for binaries.

|`DISPLAY`
|Network name of the Xorg display to connect to, if available.

|`SHELL`
|The current shell.

|`TERM`
|The name of the user's type of terminal. Used to determine the capabilities of the terminal.

|`TERMCAP`
|Database entry of the terminal escape codes to perform various terminal functions.

|`OSTYPE`
|Type of operating system.

|`MACHTYPE`
|The system's CPU architecture.

|`EDITOR`
|The user's preferred text editor.

|`PAGER`
|The user's preferred utility for viewing text one page at a time.

|`MANPATH`
|Colon-separated list of directories to search for manual pages.
|===

How to set an environment variable differs between shells.
In man:tcsh[1] and man:csh[1], use `setenv` to set environment variables.
In man:sh[1] and `bash`, use `export` to set the current environment variables.
This example sets the default `EDITOR` to `/usr/local/bin/emacs` for the man:tcsh[1] shell:

[source,shell]
....
% setenv EDITOR /usr/local/bin/emacs
....

The equivalent command for `bash` would be:

[source,shell]
....
% export EDITOR="/usr/local/bin/emacs"
....

To expand an environment variable in order to see its current setting, type a `$` character in front of its name on the command line.
For example, `echo $TERM` displays the current `$TERM` setting.

Shells treat special characters, known as meta-characters, as special representations of data.
The most common meta-character is `\*`, which represents any number of characters in a filename.
Meta-characters can be used to perform filename globbing.
For example, `echo *` is equivalent to `ls` because the shell takes all the files that match `*` and `echo` lists them on the command line.

To prevent the shell from interpreting a special character, escape it from the shell by starting it with a backslash (`\`).
For example, `echo $TERM` prints the terminal setting whereas `echo \$TERM` literally prints the string `$TERM`.

[[changing-shells]]
=== Changing the Shell

The easiest way to permanently change the default shell is to use `chsh`.
Running this command will open the editor that is configured in the `EDITOR` environment variable, which by default is set to man:vi[1].
Change the `Shell:` line to the full path of the new shell.

Alternately, use `chsh -s` which will set the specified shell without opening an editor.
For example, to change the shell to `bash`:

[source,shell]
....
% chsh -s /usr/local/bin/bash
....

[NOTE]
====
The new shell _must_ be present in `/etc/shells`.
If the shell was installed from the FreeBSD Ports Collection as described in crossref:ports[ports,Installing Applications: Packages and Ports], it should be automatically added to this file.
If it is missing, add it using this command, replacing the path with the path of the shell:

[source,shell]
....
# echo /usr/local/bin/bash >> /etc/shells
....

Then, rerun man:chsh[1].
====

=== Advanced Shell Techniques

The UNIX(R) shell is not just a command interpreter, it acts as a powerful tool which allows users to execute commands, redirect their output, redirect their input and chain commands together to improve the final command output.
When this functionality is mixed with built in commands, the user is provided with an environment that can maximize efficiency.

Shell redirection is the action of sending the output or the input of a command into another command or into a file.
To capture the output of the man:ls[1] command, for example, into a file, redirect the output:

[source,shell]
....
% ls > directory_listing.txt
....

The directory contents will now be listed in `directory_listing.txt`.
Some commands can be used to read input, such as man:sort[1].
To sort this listing, redirect the input:

[source,shell]
....
% sort < directory_listing.txt
....

The input will be sorted and placed on the screen.
To redirect that input into another file, one could redirect the output of man:sort[1] by mixing the direction:

[source,shell]
....
% sort < directory_listing.txt > sorted.txt
....

In all of the previous examples, the commands are performing redirection using file descriptors.
Every UNIX(R) system has file descriptors, which include standard input (stdin), standard output (stdout), and standard error (stderr).
Each one has a purpose, where input could be a keyboard or a mouse, something that provides input.
Output could be a screen or paper in a printer.
And error would be anything that is used for diagnostic or error messages.
All three are considered I/O based file descriptors and sometimes considered streams.

Through the use of these descriptors, the shell allows output and input to be passed around through various commands and redirected to or from a file. 
Another method of redirection is the pipe operator.

The UNIX(R) pipe operator, "|" allows the output of one command to be directly passed or directed to another program.
Basically, a pipe allows the standard output of a command to be passed as standard input to another command, for example:

[source,shell]
....
% cat directory_listing.txt | sort | less
....

In that example, the contents of `directory_listing.txt` will be sorted and the output passed to man:less[1].
This allows the user to scroll through the output at their own pace and prevent it from scrolling off the screen.

[[editors]]
== Text Editors

Most FreeBSD configuration is done by editing text files, so it is a good idea to become familiar with a text editor.
FreeBSD comes with a few as part of the base system, and many more are available in the Ports Collection.

A simple editor to learn is man:ee[1], which stands for easy editor.
To start this editor, type `ee _filename_` where _filename_ is the name of the file to be edited.
Once inside the editor, all of the commands for manipulating the editor's functions are listed at the top of the display.
The caret (`^`) represents kbd:[Ctrl], so `^e` expands to kbd:[Ctrl+e].
To leave man:ee[1], press kbd:[Esc], then choose the "leave editor" option from the main menu.
The editor will prompt to save any changes if the file has been modified.

FreeBSD also comes with more powerful text editors, such as man:vi[1], as part of the base system.
Other editors, like package:editors/emacs[] and package:editors/vim[], are part of the FreeBSD Ports Collection.
These editors offer more functionality at the expense of being more complicated to learn.
Learning a more powerful editor such as vim or Emacs can save more time in the long run.

Many applications which modify files or require typed input will automatically open a text editor.
To change the default editor, set the `EDITOR` environment variable as described in <<shells>>.

[[basics-devices]]
== Devices and Device Nodes

A device is a term used mostly for hardware-related activities in a system, including disks, printers, graphics cards, and keyboards.
When FreeBSD boots, the majority of the boot messages refer to devices being detected.
A copy of the boot messages is saved to `/var/run/dmesg.boot`.

Each device has a device name and number.
For example, `ada0` is the first SATA hard drive, while `kbd0` represents the keyboard.

Most devices in FreeBSD must be accessed through special files called device nodes, which are located in `/dev`.

[[basics-more-information]]
== Manual Pages

The most comprehensive documentation on FreeBSD is in the form of manual pages.
Nearly every program on the system comes with a short reference manual explaining the basic operation and available arguments.
These manuals can be viewed using `man`:

[source,shell]
....
% man command
....

where _command_ is the name of the command to learn about.
For example, to learn more about man:ls[1], type:

[source,shell]
....
% man ls
....

Manual pages are divided into sections which represent the type of topic.
In FreeBSD, the following sections are available:

. User commands.
. System calls and error numbers.
. Functions in the C libraries.
. Device drivers.
. File formats.
. Games and other diversions.
. Miscellaneous information.
. System maintenance and operation commands.
. System kernel interfaces.

In some cases, the same topic may appear in more than one section of the online manual.
For example, there is a `chmod` user command and a `chmod()` system call.
To tell man:man[1] which section to display, specify the section number:

[source,shell]
....
% man 1 chmod
....

This will display the manual page for the user command man:chmod[1].
References to a particular section of the online manual are traditionally placed in parenthesis in written documentation, so man:chmod[1] refers to the user command and man:chmod[2] refers to the system call.

If the name of the manual page is unknown, use `man -k` to search for keywords in the manual page descriptions:

[source,shell]
....
% man -k mail
....

This command displays a list of commands that have the keyword "mail" in their descriptions.
This is equivalent to using man:apropos[1].

To read the descriptions for all of the commands in `/usr/sbin`, type:

[source,shell]
....
% cd /usr/sbin
% man -f * | more
....

or

[source,shell]
....
% cd /usr/sbin
% whatis * |more
....

[[basics-info]]
=== GNU Info Files

FreeBSD includes several applications and utilities produced by the Free Software Foundation (FSF).
In addition to manual pages, these programs may include hypertext documents called `info` files.
These can be viewed using man:info[1] or, if package:editors/emacs[] is installed, the info mode of emacs.

To use man:info[1], type:

[source,shell]
....
% info
....

For a brief introduction, type `h`.
For a quick command reference, type `?`.