-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlab.html
More file actions
2352 lines (1969 loc) · 85.5 KB
/
Copy pathlab.html
File metadata and controls
2352 lines (1969 loc) · 85.5 KB
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Browser Linux + Docker Lab — Full Course</title>
<style>
:root {
--bg: #0d1117;
--bg-secondary: #161b22;
--bg-tertiary: #21262d;
--border: #30363d;
--text: #c9d1d9;
--text-secondary: #8b949e;
--accent: #58a6ff;
--accent-dim: #1f6feb;
--success: #3fb950;
--warning: #d29922;
--danger: #f85149;
--code-bg: #161b22;
--font-mono: "SFMono-Regular", "Consolas", "Liberation Mono", "Menlo", monospace;
--font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
}
* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
margin: 0; padding: 0;
font-family: var(--font-sans);
background: var(--bg);
color: var(--text);
line-height: 1.6;
font-size: 15px;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
/* Layout */
.page-layout {
display: flex;
min-height: 100vh;
}
.nav-sidebar {
width: 280px;
background: var(--bg-secondary);
border-right: 1px solid var(--border);
position: fixed;
top: 0; left: 0; bottom: 0;
overflow-y: auto;
padding: 20px 0;
z-index: 10;
}
.nav-sidebar h1 {
font-size: 16px;
padding: 0 20px 12px;
margin: 0 0 12px;
border-bottom: 1px solid var(--border);
color: var(--text);
}
.nav-sidebar .subtitle {
font-size: 11px;
color: var(--text-secondary);
padding: 0 20px;
margin-bottom: 16px;
text-transform: uppercase;
letter-spacing: 0.5px;
}
.nav-group {
margin-bottom: 8px;
}
.nav-group-title {
display: block;
padding: 8px 20px;
font-size: 13px;
font-weight: 600;
color: var(--text-secondary);
text-transform: uppercase;
letter-spacing: 0.5px;
cursor: pointer;
user-select: none;
}
.nav-group-title:hover { color: var(--text); }
.nav-link {
display: block;
padding: 5px 20px 5px 32px;
font-size: 13px;
color: var(--text-secondary);
border-left: 2px solid transparent;
}
.nav-link:hover { color: var(--text); background: var(--bg-tertiary); }
.nav-link.active { color: var(--accent); border-left-color: var(--accent); background: rgba(88,166,255,0.08); }
.main-content {
margin-left: 280px;
flex: 1;
max-width: 900px;
padding: 40px 48px;
}
/* Typography */
h1.content-h1 { font-size: 32px; font-weight: 700; margin: 0 0 16px; padding-bottom: 12px; border-bottom: 1px solid var(--border); }
h2 { font-size: 24px; font-weight: 600; margin: 48px 0 16px; padding-bottom: 8px; border-bottom: 1px solid var(--border); }
h3 { font-size: 18px; font-weight: 600; margin: 32px 0 12px; color: var(--accent); }
h4 { font-size: 15px; font-weight: 600; margin: 24px 0 8px; color: var(--text); }
p { margin: 0 0 16px; }
ul, ol { margin: 0 0 16px; padding-left: 24px; }
li { margin-bottom: 6px; }
strong { color: #e6edf3; }
/* Callouts */
.callout {
border-radius: 8px;
padding: 16px 20px;
margin: 20px 0;
border-left: 4px solid;
background: var(--bg-secondary);
}
.callout.info { border-left-color: var(--accent); }
.callout.warning { border-left-color: var(--warning); }
.callout.danger { border-left-color: var(--danger); }
.callout.success { border-left-color: var(--success); }
.callout-title { font-weight: 600; margin-bottom: 8px; display: flex; align-items: center; gap: 8px; }
.callout p:last-child { margin-bottom: 0; }
/* Code blocks */
.code-block {
position: relative;
background: var(--code-bg);
border: 1px solid var(--border);
border-radius: 8px;
margin: 16px 0;
overflow: hidden;
}
.code-header {
display: flex;
justify-content: space-between;
align-items: center;
padding: 8px 16px;
background: var(--bg-tertiary);
border-bottom: 1px solid var(--border);
font-size: 12px;
color: var(--text-secondary);
}
.code-header .lang { font-weight: 600; text-transform: uppercase; letter-spacing: 0.5px; }
.copy-btn {
background: transparent;
border: 1px solid var(--border);
color: var(--text-secondary);
padding: 4px 10px;
border-radius: 4px;
cursor: pointer;
font-size: 12px;
font-family: var(--font-sans);
}
.copy-btn:hover { border-color: var(--accent); color: var(--accent); }
.copy-btn.copied { color: var(--success); border-color: var(--success); }
pre {
margin: 0;
padding: 16px;
overflow-x: auto;
font-family: var(--font-mono);
font-size: 13px;
line-height: 1.6;
color: var(--text);
}
code {
font-family: var(--font-mono);
font-size: 13px;
background: var(--bg-tertiary);
padding: 2px 6px;
border-radius: 4px;
color: #ff7b72;
}
pre code { background: none; padding: 0; color: inherit; }
/* Inline highlights */
.highlight { background: rgba(88,166,255,0.12); padding: 1px 4px; border-radius: 3px; }
.cmd { color: #7ee787; }
.output { color: var(--text-secondary); font-style: italic; }
/* Tables */
table {
width: 100%;
border-collapse: collapse;
margin: 16px 0;
font-size: 14px;
}
th, td {
padding: 10px 14px;
text-align: left;
border: 1px solid var(--border);
}
th { background: var(--bg-tertiary); font-weight: 600; }
tr:nth-child(even) { background: var(--bg-secondary); }
/* Exercise box */
.exercise {
background: linear-gradient(135deg, rgba(88,166,255,0.08) 0%, rgba(63,185,80,0.05) 100%);
border: 1px solid var(--border);
border-radius: 10px;
padding: 20px 24px;
margin: 24px 0;
}
.exercise-title {
font-size: 14px;
font-weight: 700;
color: var(--accent);
text-transform: uppercase;
letter-spacing: 0.5px;
margin-bottom: 12px;
display: flex; align-items: center; gap: 8px;
}
/* Toggle for long sections */
.toggle-section {
border: 1px solid var(--border);
border-radius: 8px;
margin: 16px 0;
overflow: hidden;
}
.toggle-header {
background: var(--bg-tertiary);
padding: 12px 16px;
cursor: pointer;
display: flex;
justify-content: space-between;
align-items: center;
font-weight: 600;
user-select: none;
}
.toggle-header:hover { background: var(--border); }
.toggle-content {
padding: 16px;
display: none;
}
.toggle-content.open { display: block; }
.toggle-icon { transition: transform 0.2s; }
.toggle-icon.open { transform: rotate(90deg); }
/* Progress indicator */
.progress-bar {
position: fixed;
top: 0; left: 280px; right: 0;
height: 3px;
background: var(--bg-tertiary);
z-index: 20;
}
.progress-fill {
height: 100%;
background: linear-gradient(90deg, var(--accent), var(--success));
width: 0%;
transition: width 0.2s;
}
/* Top bar */
.top-bar {
display: none;
}
.nav-toggle-btn {
background: var(--bg-tertiary);
border: 1px solid var(--border);
color: var(--text);
padding: 6px 12px;
border-radius: 6px;
cursor: pointer;
font-size: 13px;
font-family: var(--font-sans);
display: flex;
align-items: center;
gap: 6px;
user-select: none;
}
.nav-toggle-btn:hover {
border-color: var(--accent);
color: var(--accent);
}
a:focus-visible,
.nav-toggle-btn:focus-visible {
outline: 2px solid var(--accent);
outline-offset: 2px;
border-radius: 4px;
}
@media (max-width: 900px) {
.nav-sidebar { width: 240px; }
.main-content { margin-left: 240px; padding: 24px; }
.progress-bar { left: 240px; }
}
@media (max-width: 700px) {
.nav-sidebar {
display: block;
transform: translateX(-100%);
transition: transform 0.25s ease;
width: 260px;
left: 0;
}
#nav-toggle:checked ~ .nav-sidebar {
transform: translateX(0);
}
.main-content {
margin-left: 0;
padding: 16px;
padding-top: 64px;
}
.progress-bar {
left: 0;
top: 49px;
}
.top-bar {
display: flex;
position: fixed;
top: 0;
left: 0;
right: 0;
background: var(--bg-secondary);
border-bottom: 1px solid var(--border);
padding: 12px 16px;
align-items: center;
justify-content: space-between;
z-index: 15;
}
h1.content-h1 { font-size: 26px; }
h2 { font-size: 20px; }
h3 { font-size: 16px; }
}
</style>
</head>
<body>
<div class="progress-bar"><div class="progress-fill" id="progress-fill"></div></div>
<div class="page-layout">
<input type="checkbox" id="nav-toggle" hidden>
<nav class="nav-sidebar" id="nav-sidebar">
<h1>🐧 Linux + Docker Lab</h1>
<div class="subtitle">Full Course Curriculum</div>
<div class="nav-group">
<span class="nav-group-title">Getting Started</span>
<a class="nav-link" href="#intro">Introduction</a>
<a class="nav-link" href="#environment">Your Environment</a>
<a class="nav-link" href="#first-commands">First Commands</a>
</div>
<div class="nav-group">
<span class="nav-group-title">Module 1: Linux Basics</span>
<a class="nav-link" href="#m1-shell">Shell & Navigation</a>
<a class="nav-link" href="#m1-files">Files & Permissions</a>
<a class="nav-link" href="#m1-pipes">Pipes & Redirection</a>
<a class="nav-link" href="#m1-env">Environment Variables</a>
<a class="nav-link" href="#m1-packages">Package Management</a>
</div>
<div class="nav-group">
<span class="nav-group-title">Module 2: System Admin</span>
<a class="nav-link" href="#m2-users">Users & Groups</a>
<a class="nav-link" href="#m2-processes">Process Management</a>
<a class="nav-link" href="#m2-disk">Disk & Filesystems</a>
<a class="nav-link" href="#m2-network">Network Basics</a>
<a class="nav-link" href="#m2-firewall">Firewall (iptables)</a>
</div>
<div class="nav-group">
<span class="nav-group-title">Module 3: Shell Scripting</span>
<a class="nav-link" href="#m3-intro">Script Basics</a>
<a class="nav-link" href="#m3-variables">Variables & Arguments</a>
<a class="nav-link" href="#m3-conditions">Conditionals</a>
<a class="nav-link" href="#m3-loops">Loops</a>
<a class="nav-link" href="#m3-functions">Functions</a>
<a class="nav-link" href="#m3-text">Text Processing</a>
</div>
<div class="nav-group">
<span class="nav-group-title">Module 4: Docker</span>
<a class="nav-link" href="#m4-containers">Containers</a>
<a class="nav-link" href="#m4-images">Images & Dockerfile</a>
<a class="nav-link" href="#m4-networking">Docker Networking</a>
<a class="nav-link" href="#m4-compose">Docker Compose</a>
<a class="nav-link" href="#m4-microservices">Microservices Lab</a>
</div>
<div class="nav-group">
<span class="nav-group-title">Module 5: Database</span>
<a class="nav-link" href="#m5-mysql">MySQL with Docker</a>
<a class="nav-link" href="#m5-sql">SQL Basics</a>
<a class="nav-link" href="#m5-joins">JOINs & Queries</a>
</div>
<div class="nav-group">
<span class="nav-group-title">Module 6: Kubernetes</span>
<a class="nav-link" href="#m6-concepts">Core Concepts</a>
<a class="nav-link" href="#m6-resources">Resources & kubectl</a>
<a class="nav-link" href="#m6-yaml">YAML Manifests</a>
</div>
</nav>
<main class="main-content" id="main-content">
<div class="top-bar">
<label for="nav-toggle" class="nav-toggle-btn">☰ Menu</label>
<span style="font-weight:600;font-size:14px;">Linux + Docker Lab</span>
</div>
<!-- INTRODUCTION -->
<h1 class="content-h1" id="intro">Browser Linux + Docker Lab</h1>
<p>Welcome to the <strong>unified hands-on lab</strong> for Linux system administration, shell scripting, Docker containerization, and database management. Everything in this course runs inside a real Alpine Linux virtual machine that boots directly in your browser.</p>
<div class="callout info">
<div class="callout-title">ℹ️ What makes this lab special</div>
<p>You are running a <strong>real 32-bit x86 Alpine Linux</strong> system with a real Linux kernel, Docker daemon, and full network access — all inside your browser via the <a href="https://github.com/copy/v86" target="_blank">v86 emulator</a>. There is no simulation; every command you run executes on a genuine Linux kernel.</p>
</div>
<h2 id="environment">Your Environment</h2>
<table>
<tr><th>Component</th><th>Version / Details</th></tr>
<tr><td>Operating System</td><td>Alpine Linux 3.21 (x86, 32-bit)</td></tr>
<tr><td>Kernel</td><td>linux-virt 6.12.87</td></tr>
<tr><td>Docker</td><td>27.3.1 (pre-installed)</td></tr>
<tr><td>Package Manager</td><td><code>apk</code> (Alpine Package Keeper)</td></tr>
<tr><td>Shell</td><td><code>bash</code> and <code>ash</code> (BusyBox)</td></tr>
<tr><td>Init System</td><td>OpenRC</td></tr>
<tr><td>Network</td><td>DHCP via virtio-net, NAT to internet</td></tr>
<tr><td>Preloaded Image</td><td><code>i386/alpine:3.22</code> tar archive</td></tr>
</table>
<div class="callout warning">
<div class="callout-title">⚠️ Architecture Note</div>
<p>This VM runs on a <strong>32-bit x86 (i386/i686)</strong> CPU. Docker images must use the <code>i386/...</code> prefix or be multi-arch. Running <code>amd64</code> images will produce <code>exec format error</code>. Alpine-based images work best: <code>i386/alpine:3.22</code>, <code>i386/nginx</code>, etc.</p>
</div>
<h2 id="first-commands">First Commands</h2>
<p>After the VM boots and the status shows <strong>"Docker Ready"</strong>, try these commands to verify your environment:</p>
<div class="code-block">
<div class="code-header"><span class="lang">Shell</span><button class="copy-btn" onclick="copyCode(this)">Copy</button></div>
<pre><code># Show Alpine version
cat /etc/alpine-release
# Show architecture
uname -m
# Show running kernel version
uname -r
# Check Docker is running
docker version
# Run your first container
docker run --rm i386/alpine:3.22 echo "Hello from Docker inside browser!"</code></pre>
</div>
<div class="exercise">
<div class="exercise-title">🎯 Exercise 0: Verify Environment</div>
<p>Run each command above. Confirm you see <code>i686</code> or <code>i386</code> from <code>uname -m</code>, and that Docker responds with both Client and Server versions. If Docker is not ready, wait for the boot log to show <em>"Docker: daemon is running"</em>.</p>
</div>
<hr style="border-color: var(--border); margin: 48px 0;">
<!-- MODULE 1: LINUX BASICS -->
<h1 class="content-h1" id="m1-shell">Module 1: Linux Fundamentals</h1>
<p>This module covers the essential skills every Linux user needs: navigating the filesystem, managing files, understanding permissions, and controlling input/output streams.</p>
<h2>1.1 Shell & Navigation</h2>
<p>The <strong>shell</strong> is the command-line interpreter that takes your typed commands and translates them into instructions for the computer. On Alpine, the default shell is <code>ash</code> (BusyBox), but <code>bash</code> is also installed.</p>
<h3>Basic Navigation Commands</h3>
<div class="code-block">
<div class="code-header"><span class="lang">Shell</span><button class="copy-btn" onclick="copyCode(this)">Copy</button></div>
<pre><code># Print Working Directory — show where you are
pwd
# List files and directories
ls
ls -l # Long format with permissions
ls -la # Include hidden files
ls -lh # Human-readable sizes
# Change directory
cd / # Go to root
cd ~ # Go to home directory
cd .. # Go up one level
cd - # Go to previous directory
# Create and remove directories
mkdir mydir
mkdir -p mydir/subdir/nested # Create nested directories
rmdir mydir # Remove empty directory
rm -r mydir # Remove directory and contents
# Current shell type
echo $SHELL
# Show available shells
cat /etc/shells</code></pre>
</div>
<h3>Directory Structure</h3>
<p>Linux organizes all files in a single tree starting at <code>/</code> (root). Key directories on Alpine:</p>
<table>
<tr><th>Directory</th><th>Purpose</th></tr>
<tr><td><code>/bin</code></td><td>Essential user commands (busybox binaries)</td></tr>
<tr><td><code>/sbin</code></td><td>System administration binaries</td></tr>
<tr><td><code>/etc</code></td><td>System configuration files</td></tr>
<tr><td><code>/home</code></td><td>User home directories</td></tr>
<tr><td><code>/root</code></td><td>Home directory for root user</td></tr>
<tr><td><code>/var</code></td><td>Variable data (logs, caches, mail)</td></tr>
<tr><td><code>/tmp</code></td><td>Temporary files</td></tr>
<tr><td><code>/proc</code></td><td>Virtual filesystem for process/kernel info</td></tr>
<tr><td><code>/sys</code></td><td>Virtual filesystem for system info</td></tr>
<tr><td><code>/dev</code></td><td>Device files</td></tr>
<tr><td><code>/usr</code></td><td>User programs and data</td></tr>
<tr><td><code>/lib</code></td><td>Essential shared libraries</td></tr>
<tr><td><code>/mnt</code></td><td>Temporary mount points</td></tr>
<tr><td><code>/media</code></td><td>Removable media mount points</td></tr>
</table>
<div class="exercise">
<div class="exercise-title">🎯 Exercise 1.1: Explore the Filesystem</div>
<ol>
<li>Navigate to <code>/bin</code> and list its contents. How many commands are there?</li>
<li>Check what <code>ls</code> really is: <code>ls -l /bin/ls</code> and <code>file /bin/ls</code></li>
<li>On Alpine, most binaries are symlinks to <code>/bin/busybox</code>. Verify: <code>ls -l /bin/cat /bin/ls /bin/grep</code></li>
<li>Count total commands: <code>ls /bin | wc -l</code></li>
</ol>
</div>
<h2 id="m1-files">1.2 Files & Permissions</h2>
<p>Everything in Linux is a file. Understanding file permissions is critical for system security.</p>
<h3>File Operations</h3>
<div class="code-block">
<div class="code-header"><span class="lang">Shell</span><button class="copy-btn" onclick="copyCode(this)">Copy</button></div>
<pre><code># Create files
touch newfile.txt
# View file contents
cat file.txt # Print entire file
head -20 file.txt # First 20 lines
tail -20 file.txt # Last 20 lines
less file.txt # Paginated view (q to quit)
# Copy, move, delete
cp file.txt backup.txt
mv file.txt renamed.txt
rm file.txt
rm -i file.txt # Confirm before deleting
# Search inside files
grep "pattern" file.txt
grep -i "pattern" file.txt # Case-insensitive
grep -r "pattern" /etc/ # Recursive search
grep -n "pattern" file.txt # Show line numbers
# File type and size
file /bin/sh
stat /etc/passwd
du -sh /var/log # Disk usage
df -h # Free disk space</code></pre>
</div>
<h3>Understanding Permissions</h3>
<p>Run <code>ls -l</code> and you will see lines like:</p>
<div class="code-block">
<div class="code-header"><span class="lang">Output</span><button class="copy-btn" onclick="copyCode(this)">Copy</button></div>
<pre><code>-rw-r--r-- 1 root root 1234 Jan 15 10:00 file.txt
drwxr-xr-x 2 root root 4096 Jan 15 09:30 mydir
lrwxrwxrwx 1 root root 4 Jan 15 08:00 link -> file</code></pre>
</div>
<table>
<tr><th>Position</th><th>Meaning</th></tr>
<tr><td>1st char</td><td><code>-</code> file, <code>d</code> directory, <code>l</code> symlink</td></tr>
<tr><td>2-4</td><td>Owner permissions: read (r), write (w), execute (x)</td></tr>
<tr><td>5-7</td><td>Group permissions</td></tr>
<tr><td>8-10</td><td>Others (world) permissions</td></tr>
</table>
<div class="code-block">
<div class="code-header"><span class="lang">Shell</span><button class="copy-btn" onclick="copyCode(this)">Copy</button></div>
<pre><code># Change permissions
chmod 755 script.sh # rwxr-xr-x
chmod u+x script.sh # Add execute for owner
chmod go-w file.txt # Remove write for group and others
# Change owner
chown user:group file.txt
chown -R user:group /mydir # Recursive
# Symbolic notation reference
# u = user (owner), g = group, o = others, a = all
# + = add, - = remove, = = set exactly
chmod u=rwx,go=rx file</code></pre>
</div>
<div class="exercise">
<div class="exercise-title">🎯 Exercise 1.2: Permission Practice</div>
<ol>
<li>Create a file: <code>touch /tmp/myfile</code> and check its permissions with <code>ls -l /tmp/myfile</code></li>
<li>Create a script: <code>echo '#!/bin/sh' > /tmp/hello.sh && echo 'echo Hello' >> /tmp/hello.sh</code></li>
<li>Try to run it: <code>/tmp/hello.sh</code> — it should fail with "Permission denied"</li>
<li>Make it executable: <code>chmod +x /tmp/hello.sh</code> and run again</li>
<li>Remove execute permission from others: <code>chmod o-x /tmp/hello.sh</code></li>
</ol>
</div>
<h2 id="m1-pipes">1.3 Pipes & Redirection</h2>
<p>Linux has three standard I/O streams: <strong>stdin</strong> (0), <strong>stdout</strong> (1), and <strong>stderr</strong> (2). Redirection and piping let you combine commands in powerful ways.</p>
<div class="code-block">
<div class="code-header"><span class="lang">Shell</span><button class="copy-btn" onclick="copyCode(this)">Copy</button></div>
<pre><code># Redirect stdout to file
ls /etc > files.txt
# Redirect and append
echo "new line" >> files.txt
# Redirect stderr
ls /nonexistent 2> errors.log
# Redirect both stdout and stderr
command > output.log 2>&1
command &> output.log # Bash shorthand
# Discard output
command > /dev/null 2>&1
# Pipe: send stdout of one command to stdin of another
ls /etc | wc -l # Count files in /etc
cat /etc/passwd | grep root # Find root entries
ps aux | grep docker # Find docker processes
# Pipe with stderr through pipe
cat /etc/passwd /nonexistent 2>&1 | grep -i error
# Here document
cat << EOF > /tmp/config.txt
name=lab
version=1.0
EOF
# xargs: build commands from stdin
find /etc -name "*.conf" | xargs ls -la</code></pre>
</div>
<div class="callout info">
<div class="callout-title">💡 Pipe Chain Examples</div>
<p><code>cat /var/log/messages | grep "error" | sort | uniq -c | sort -nr</code> — finds all error lines, counts unique occurrences, and sorts by frequency (most common first).</p>
</div>
<h2 id="m1-env">1.4 Environment Variables</h2>
<p>Environment variables store configuration that programs can read. They are essential for scripting and application configuration.</p>
<div class="code-block">
<div class="code-header"><span class="lang">Shell</span><button class="copy-btn" onclick="copyCode(this)">Copy</button></div>
<pre><code># List all environment variables
env
printenv
# Show a specific variable
echo $HOME
echo $PATH
echo $SHELL
# Set a variable (local to current shell)
MY_VAR="hello world"
echo $MY_VAR
# Export to make it available to child processes
export MY_VAR="hello world"
# Add to PATH
export PATH="$PATH:/my/custom/bin"
# Remove a variable
unset MY_VAR
# Common environment variables on Alpine
env | grep -E "^(HOME|PATH|SHELL|USER|PWD|TERM)="</code></pre>
</div>
<div class="exercise">
<div class="exercise-title">🎯 Exercise 1.3: Variables in Action</div>
<ol>
<li>Set a variable: <code>PROJECT="browser-lab"</code></li>
<li>Verify with <code>echo $PROJECT</code></li>
<li>Run <code>env | grep PROJECT</code> — why is it empty?</li>
<li>Export it: <code>export PROJECT</code> and check <code>env</code> again</li>
<li>Run a sub-shell: <code>sh -c 'echo $PROJECT'</code> — does it work now?</li>
</ol>
</div>
<h2 id="m1-packages">1.5 Package Management (apk)</h2>
<p>Alpine uses <code>apk</code> (Alpine Package Keeper) instead of <code>apt</code> or <code>yum</code>. The original course materials use Debian commands, so this is an important adaptation.</p>
<div class="callout warning">
<div class="callout-title">⚠️ Debian vs Alpine Commands</div>
<table>
<tr><th>Task</th><th>Debian/Ubuntu</th><th>Alpine Linux</th></tr>
<tr><td>Update package list</td><td><code>apt update</code></td><td><code>apk update</code></td></tr>
<tr><td>Install package</td><td><code>apt install pkg</code></td><td><code>apk add pkg</code></td></tr>
<tr><td>Remove package</td><td><code>apt remove pkg</code></td><td><code>apk del pkg</code></td></tr>
<tr><td>Search package</td><td><code>apt search pkg</code></td><td><code>apk search pkg</code></td></tr>
<tr><td>Package info</td><td><code>dpkg -l | grep pkg</code></td><td><code>apk info pkg</code></td></tr>
<tr><td>Upgrade all</td><td><code>apt upgrade</code></td><td><code>apk upgrade</code></td></tr>
</table>
</div>
<div class="code-block">
<div class="code-header"><span class="lang">Shell</span><button class="copy-btn" onclick="copyCode(this)">Copy</button></div>
<pre><code># Update package index
apk update
# Install packages
apk add curl wget vim nano git
# Install with no cache (saves space in Docker)
apk add --no-cache curl
# Remove a package
apk del vim
# Search for packages
apk search python3
apk search -v python3 # With descriptions
# Show installed packages
apk info
# Show package details
apk info curl
# Show what files a package owns
apk info -L curl
# Find which package owns a file
apk info --who-owns /bin/curl</code></pre>
</div>
<div class="exercise">
<div class="exercise-title">🎯 Exercise 1.4: Package Management</div>
<ol>
<li>Update the package index: <code>apk update</code></li>
<li>Search for the nginx package: <code>apk search nginx</code></li>
<li>Install <code>curl</code> and <code>jq</code>: <code>apk add curl jq</code></li>
<li>Test curl: <code>curl -s https://httpbin.org/get | jq '.origin'</code></li>
<li>Check what curl owns: <code>apk info -L curl | head -20</code></li>
</ol>
</div>
<hr style="border-color: var(--border); margin: 48px 0;">
<!-- MODULE 2: SYSTEM ADMINISTRATION -->
<h1 class="content-h1" id="m2-users">Module 2: System Administration</h1>
<p>This module covers user management, process control, disk configuration, networking, and firewall rules — the daily work of a Linux system administrator.</p>
<h2>2.1 Users & Groups</h2>
<p>Linux is a multi-user system. Every file and process is owned by a user and a group. The <code>root</code> user has unlimited privileges.</p>
<div class="code-block">
<div class="code-header"><span class="lang">Shell</span><button class="copy-btn" onclick="copyCode(this)">Copy</button></div>
<pre><code># Show current user
whoami
id
# Show user info
id root
id $(whoami)
# User database files
cat /etc/passwd # User accounts
cat /etc/shadow # Password hashes (root only)
cat /etc/group # Group definitions
# Add a user (Alpine uses adduser script)
adduser -D -s /bin/sh student
# Set password
passwd student
# Add user to a group
addgroup student docker
# Modify user
usermod -s /bin/bash student
# Delete user
deluser student
# Switch user
su - student
# Run command as root (you are already root in this lab)
sudo whoami</code></pre>
</div>
<p>The <code>/etc/passwd</code> file format:</p>
<div class="code-block">
<div class="code-header"><span class="lang">Output</span><button class="copy-btn" onclick="copyCode(this)">Copy</button></div>
<pre><code>root:x:0:0:root:/root:/bin/sh
# format: username:password:UID:GID:comment:home:shell</code></pre>
</div>
<h2 id="m2-processes">2.2 Process Management</h2>
<p>Every running program is a <strong>process</strong>. Linux provides powerful tools to view, control, and manage processes.</p>
<div class="code-block">
<div class="code-header"><span class="lang">Shell</span><button class="copy-btn" onclick="copyCode(this)">Copy</button></div>
<pre><code># List processes
ps aux # All processes, detailed
ps -ef # Full format
ps aux | grep docker
# Real-time process viewer
top # Basic
top -b -n 1 # Batch mode, single snapshot
# Better process viewer (install if needed)
# apk add htop # Not available on i386; use top instead
# Process tree
pstree
# Find process by name
pgrep docker
pidof dockerd
# Send signals to processes
kill PID # Graceful termination (SIGTERM)
kill -9 PID # Force kill (SIGKILL)
killall dockerd # Kill by name
# Background and foreground
sleep 60 & # Run in background
jobs # List background jobs
fg %1 # Bring job 1 to foreground
bg %1 # Resume job 1 in background
# Process priority (nice values)
nice -n 10 command # Run with lower priority
renice -n 5 -p PID # Change priority of running process
# Show open files by process
lsof -p PID
lsof -i :80 # What is using port 80?</code></pre>
</div>
<div class="callout info">
<div class="callout-title">💡 Common Process States</div>
<p><code>R</code> = Running, <code>S</code> = Sleeping (interruptible), <code>D</code> = Uninterruptible sleep, <code>T</code> = Stopped, <code>Z</code> = Zombie (defunct). See full list with <code>man ps</code>.</p>
</div>
<h2 id="m2-disk">2.3 Disk & Filesystems</h2>
<p>Understanding disk layout, partitions, and filesystems is essential for storage management.</p>
<div class="code-block">
<div class="code-header"><span class="lang">Shell</span><button class="copy-btn" onclick="copyCode(this)">Copy</button></div>
<pre><code># Disk space usage
df -h # Human-readable
df -hT # With filesystem types
# Directory sizes
du -sh /var/log
du -sh /* # Size of each top-level directory
# List block devices
lsblk
fdisk -l # Partition tables
# Filesystem info (Alpine uses ext4 for root, tmpfs for some mounts)
mount | column -t
cat /proc/filesystems # Supported filesystems
cat /proc/partitions # Partition info
# Create a filesystem (careful!)
# mkfs.ext4 /dev/sda1
# Mount and unmount
mount /dev/sda1 /mnt
umount /mnt
# Check /etc/fstab for auto-mount rules
cat /etc/fstab
# Swap
free -m # Memory and swap usage
cat /proc/swaps # Swap devices
# The dd command — low-level data copy
dd if=/dev/zero of=/tmp/testfile bs=1M count=100 # Create 100MB file
dd if=/dev/urandom of=/tmp/random bs=1K count=10 # Random data</code></pre>
</div>
<div class="exercise">
<div class="exercise-title">🎯 Exercise 2.1: Storage Analysis</div>
<ol>
<li>Check disk usage: <code>df -h</code> — how much free space do you have?</li>
<li>Find largest directories: <code>du -sh /var/* /tmp/*</code></li>
<li>Check what filesystem types are in use: <code>mount | awk '{print $1, $5}' | sort | uniq</code></li>
<li>Create a 50MB test file with <code>dd</code> and verify its size</li>
</ol>
</div>
<h2 id="m2-network">2.4 Network Basics</h2>
<p>Networking is fundamental to modern Linux systems. This section covers the essential network commands available on Alpine.</p>
<div class="code-block">
<div class="code-header"><span class="lang">Shell</span><button class="copy-btn" onclick="copyCode(this)">Copy</button></div>
<pre><code># Interface configuration
ip addr show
ip addr show eth0
ifconfig # Legacy but available via busybox
# Routing
ip route
route -n
# DNS resolution
nslookup google.com
dig google.com
host google.com
cat /etc/resolv.conf # DNS servers
# Connectivity tests
ping -c 4 8.8.8.8
ping -c 4 google.com
# Trace route
traceroute google.com # Install: apk add traceroute
mtr google.com # Install: apk add mtr
# Port scanning and connections
netstat -tlnp # Listening ports with PIDs
ss -tlnp # Modern replacement for netstat
# ARP table
ip neigh
arp -a
# Network stats
cat /proc/net/dev # Interface statistics
# Download files
wget https://example.com/file.txt
curl -O https://example.com/file.txt
curl -s https://api.ipify.org # Show public IP
# Check if a port is open
nc -zv google.com 443 # Install: apk add netcat-openbsd
telnet google.com 80 # Test TCP connection</code></pre>
</div>
<div class="exercise">
<div class="exercise-title">🎯 Exercise 2.2: Network Exploration</div>
<ol>
<li>Install traceroute: <code>apk add traceroute</code> and trace to <code>8.8.8.8</code></li>
<li>Check your DNS servers: <code>cat /etc/resolv.conf</code></li>
<li>Find your public IP: <code>curl -s https://api.ipify.org</code></li>
<li>Check listening ports: <code>ss -tlnp</code> — what services are running?</li>
<li>Use <code>netstat -tlnp</code> to confirm Docker is listening</li>
</ol>
</div>
<h2 id="m2-firewall">2.5 Firewall (iptables)</h2>
<p>iptables is the Linux firewall framework. Alpine includes iptables and ip6tables. Docker manipulates iptables rules automatically for container networking.</p>
<div class="code-block">
<div class="code-header"><span class="lang">Shell</span><button class="copy-btn" onclick="copyCode(this)">Copy</button></div>
<pre><code># List all rules
iptables -L -v -n
# List rules with line numbers
iptables -L INPUT -n --line-numbers
# Show NAT rules (Docker uses these extensively)
iptables -t nat -L -n -v
# Default chains: INPUT, FORWARD, OUTPUT
# Default tables: filter, nat, mangle, raw
# Allow incoming SSH (example)
iptables -A INPUT -p tcp --dport 22 -j ACCEPT
# Block an IP
iptables -A INPUT -s 192.168.1.100 -j DROP
# Save rules (Alpine)
iptables-save > /etc/iptables/rules.v4
# Docker's iptables impact
iptables -L FORWARD -n -v # Docker creates forwarding rules
iptables -t nat -L DOCKER # Docker NAT rules for port mapping</code></pre>
</div>