-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuybhys-2024-openssh-workshop.html
1466 lines (1466 loc) · 80.8 KB
/
uybhys-2024-openssh-workshop.html
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 xmlns="http://www.w3.org/1999/xhtml" lang="" xml:lang="">
<head>
<meta charset="utf-8" />
<meta name="generator" content="pandoc" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes" />
<meta name="author" content="William Robinet (Conostix S.A.)" />
<title>Exploring OpenSSH: Hands-On Workshop for Beginners</title>
<style>
html {
line-height: 1.5;
font-family: Georgia, serif;
font-size: 20px;
color: #1a1a1a;
background-color: #fdfdfd;
}
body {
margin: 0 auto;
max-width: 36em;
padding-left: 50px;
padding-right: 50px;
padding-top: 50px;
padding-bottom: 50px;
hyphens: auto;
overflow-wrap: break-word;
text-rendering: optimizeLegibility;
font-kerning: normal;
}
@media (max-width: 600px) {
body {
font-size: 0.9em;
padding: 1em;
}
h1 {
font-size: 1.8em;
}
}
@media print {
body {
background-color: transparent;
color: black;
font-size: 12pt;
}
p, h2, h3 {
orphans: 3;
widows: 3;
}
h2, h3, h4 {
page-break-after: avoid;
}
}
p {
margin: 1em 0;
}
a {
color: #1a1a1a;
}
a:visited {
color: #1a1a1a;
}
img {
max-width: 100%;
}
h1, h2, h3, h4, h5, h6 {
margin-top: 1.4em;
}
h5, h6 {
font-size: 1em;
font-style: italic;
}
h6 {
font-weight: normal;
}
ol, ul {
padding-left: 1.7em;
margin-top: 1em;
}
li > ol, li > ul {
margin-top: 0;
}
blockquote {
margin: 1em 0 1em 1.7em;
padding-left: 1em;
border-left: 2px solid #e6e6e6;
color: #606060;
}
code {
font-family: Menlo, Monaco, 'Lucida Console', Consolas, monospace;
font-size: 85%;
margin: 0;
}
pre {
margin: 1em 0;
overflow: auto;
}
pre code {
padding: 0;
overflow: visible;
overflow-wrap: normal;
}
.sourceCode {
background-color: transparent;
overflow: visible;
}
hr {
background-color: #1a1a1a;
border: none;
height: 1px;
margin: 1em 0;
}
table {
margin: 1em 0;
border-collapse: collapse;
width: 100%;
overflow-x: auto;
display: block;
font-variant-numeric: lining-nums tabular-nums;
}
table caption {
margin-bottom: 0.75em;
}
tbody {
margin-top: 0.5em;
border-top: 1px solid #1a1a1a;
border-bottom: 1px solid #1a1a1a;
}
th {
border-top: 1px solid #1a1a1a;
padding: 0.25em 0.5em 0.25em 0.5em;
}
td {
padding: 0.125em 0.5em 0.25em 0.5em;
}
header {
margin-bottom: 4em;
text-align: center;
}
#TOC li {
list-style: none;
}
#TOC ul {
padding-left: 1.3em;
}
#TOC > ul {
padding-left: 0;
}
#TOC a:not(:hover) {
text-decoration: none;
}
code{white-space: pre-wrap;}
span.smallcaps{font-variant: small-caps;}
span.underline{text-decoration: underline;}
div.column{display: inline-block; vertical-align: top; width: 50%;}
div.hanging-indent{margin-left: 1.5em; text-indent: -1.5em;}
ul.task-list{list-style: none;}
pre > code.sourceCode { white-space: pre; position: relative; }
pre > code.sourceCode > span { display: inline-block; line-height: 1.25; }
pre > code.sourceCode > span:empty { height: 1.2em; }
.sourceCode { overflow: visible; }
code.sourceCode > span { color: inherit; text-decoration: inherit; }
div.sourceCode { margin: 1em 0; }
pre.sourceCode { margin: 0; }
@media screen {
div.sourceCode { overflow: auto; }
}
@media print {
pre > code.sourceCode { white-space: pre-wrap; }
pre > code.sourceCode > span { text-indent: -5em; padding-left: 5em; }
}
pre.numberSource code
{ counter-reset: source-line 0; }
pre.numberSource code > span
{ position: relative; left: -4em; counter-increment: source-line; }
pre.numberSource code > span > a:first-child::before
{ content: counter(source-line);
position: relative; left: -1em; text-align: right; vertical-align: baseline;
border: none; display: inline-block;
-webkit-touch-callout: none; -webkit-user-select: none;
-khtml-user-select: none; -moz-user-select: none;
-ms-user-select: none; user-select: none;
padding: 0 4px; width: 4em;
background-color: #ffffff;
color: #a0a0a0;
}
pre.numberSource { margin-left: 3em; border-left: 1px solid #a0a0a0; padding-left: 4px; }
div.sourceCode
{ color: #1f1c1b; background-color: #ffffff; }
@media screen {
pre > code.sourceCode > span > a:first-child::before { text-decoration: underline; }
}
code span { color: #1f1c1b; } /* Normal */
code span.al { color: #ffff00; font-weight: bold; } /* Alert */
code span.an { color: #ca60ca; } /* Annotation */
code span.at { color: #0057ae; } /* Attribute */
code span.bn { color: #b08000; } /* BaseN */
code span.bu { color: #0000ff; font-weight: bold; } /* BuiltIn */
code span.cf { color: #1f1c1b; font-weight: bold; } /* ControlFlow */
code span.ch { color: #924c9d; } /* Char */
code span.cn { color: #aa5500; } /* Constant */
code span.co { color: #898887; } /* Comment */
code span.cv { color: #0095ff; } /* CommentVar */
code span.do { color: #ffffff; font-weight: bold; } /* Documentation */
code span.dt { color: #0057ae; } /* DataType */
code span.dv { color: #b08000; } /* DecVal */
code span.er { color: #bf0303; text-decoration: underline; } /* Error */
code span.ex { color: #0095ff; font-weight: bold; } /* Extension */
code span.fl { color: #b08000; } /* Float */
code span.fu { color: #644a9b; } /* Function */
code span.im { color: #00ff00; font-weight: bold; } /* Import */
code span.in { color: #b08000; } /* Information */
code span.kw { color: #ff0000; font-weight: bold; } /* Keyword */
code span.op { color: #1f1c1b; } /* Operator */
code span.ot { color: #006e28; } /* Other */
code span.pp { color: #006e28; } /* Preprocessor */
code span.re { color: #0057ae; background-color: #e0e9f8; } /* RegionMarker */
code span.sc { color: #3daee9; } /* SpecialChar */
code span.ss { color: #ff5500; } /* SpecialString */
code span.st { color: #bf0303; } /* String */
code span.va { color: #0057ae; } /* Variable */
code span.vs { color: #bf0303; } /* VerbatimString */
code span.wa { color: #bf0303; } /* Warning */
.display.math{display: block; text-align: center; margin: 0.5rem auto;}
</style>
<link rel="stylesheet" href="./ws_gen_resources/style.css">
<script src="./ws_gen_resources/jquery-2.1.3.min.js"></script>
<script src="./ws_gen_resources/twemoji.min.js" crossorigin="anonymous"></script>
<script>
$(document).ready
(
function()
{
twemoji.parse(document.body);
}
);
</script>
</head>
<body>
<header id="title-block-header">
<h1 class="title">Exploring OpenSSH: Hands-On Workshop for
Beginners</h1>
<p class="author">William Robinet (Conostix S.A.)</p>
</header>
<p><strong>Unlock Your Brain, Harden Your System 2024 -
Brest</strong></p>
<p><strong>Exploring OpenSSH: Hands-On Workshop for
Beginners</strong></p>
<p>William Robinet (Conostix S.A.) - 2024-11-08</p>
<p>Matrix Room: <em>https://t.ly/sQFh-</em> – GitHub Repository:
<em>https://t.ly/YrzJT</em></p>
<p>Wi-Fi SSID: <em>uybhys2024_openssh_workshop</em> – Wi-Fi password:
<em>uybhys2024</em></p>
<p>Docker images download –> <em>http://192.168.178.2</em></p>
<hr />
<!--config:
margins:
left: 10
right: 10
-->
<h1 id="about-me">About me</h1>
<ul>
<li>Introduced to Open Source & Free Software around the end of the
90’s</li>
<li>CompSci studies, work in IT at Conostix S.A. - AS197692</li>
<li>Open Source contributions:
<ul>
<li>ssldump improvements (build system, bug fixes, JSON output, IPv6
& ja3(s), …)</li>
<li>asn1template: painless ASN.1 editing</li>
</ul></li>
<li>Conference workshops & presentations</li>
<li>🎸 🏃 🚵 🔭 ⏚ …</li>
<li>Contact info
<ul>
<li>GitHub: <strong>https://github.com/wllm-rbnt</strong></li>
<li>Mastodon: <strong>https://infosec.exchange/<span class="citation"
data-cites="wr">@wr</span></strong></li>
</ul></li>
</ul>
<hr />
<!--config:
margins:
left: 10
right: 10
-->
<h1 id="before-we-begin-12">Before we begin 1/2</h1>
<h2 id="workshop-resources">Workshop resources</h2>
<p>Matrix Room:</p>
<p><code>https://matrix.to/#/#UYBHYS_2024-OpenSSH_Workshop:matrix.org</code></p>
<p>Used to exchange links and commands.</p>
<p>Workshop repository:</p>
<p><strong>https://github.com/wllm-rbnt/uybhys-2024-openssh-workshop</strong></p>
<div class="sourceCode" id="cb1"><pre
class="sourceCode bash"><code class="sourceCode bash"><span id="cb1-1"><a href="#cb1-1" aria-hidden="true" tabindex="-1"></a><span class="fu">git</span> clone https://github.com/wllm-rbnt/uybhys-2024-openssh-workshop.git</span>
<span id="cb1-2"><a href="#cb1-2" aria-hidden="true" tabindex="-1"></a><span class="bu">cd</span> uybhys-2024-openssh-workshop</span></code></pre></div>
<p>Shorter URLs:</p>
<ul>
<li>Matrix Room -> <strong>https://t.ly/sQFh-</strong></li>
<li>Repository -> <strong>https://t.ly/YrzJT</strong></li>
</ul>
<hr />
<!--config:
margins:
left: 10
right: 10
-->
<h1 id="before-we-begin-22">Before we begin 2/2</h1>
<p>Slides are written in Markdown</p>
<p>Get the <em>PDF</em>/<em>HTML</em> versions or use <em>patat</em> to
render the presentation in your terminal</p>
<p>Go to release page
<strong>https://github.com/jaspervdj/patat/releases</strong> and
download version 0.12.0.1</p>
<p>or</p>
<div class="sourceCode" id="cb2"><pre
class="sourceCode bash"><code class="sourceCode bash"><span id="cb2-1"><a href="#cb2-1" aria-hidden="true" tabindex="-1"></a><span class="fu">wget</span> https://github.com/jaspervdj/patat/releases/download/v0.12.0.1/patat-v0.12.0.1-linux-x86_64.tar.gz</span>
<span id="cb2-2"><a href="#cb2-2" aria-hidden="true" tabindex="-1"></a><span class="fu">tar</span> xzf patat-v0.12.0.1-linux-x86_64.tar.gz patat-v0.12.0.1-linux-x86_64/patat</span>
<span id="cb2-3"><a href="#cb2-3" aria-hidden="true" tabindex="-1"></a><span class="ex">patat-v0.12.0.1-linux-x86_64/patat</span> uybhys-2024-openssh-workshop.patat.md</span></code></pre></div>
<p>The Markdown version can be converted to PDF & HTML by using the
provided <em>ws_gen</em> script (<em>pandoc</em> & <em>chromium</em>
must be installed first)</p>
<hr />
<!--config:
wrap: false
margins:
left: 10
right: 10
-->
<h1 id="local-machine-setup-12">Local Machine Setup (1/2)</h1>
<h2 id="docker-installation">Docker Installation</h2>
<p>Reference documentation:
<strong>https://docs.docker.com/engine/install/</strong></p>
<p>This will provide <code>docker compose</code> v2 command (with a
space).</p>
<p>On Debian 12 (bookworm), the following command will provide
<code>docker-compose</code> v1 command (with a dash).</p>
<div class="sourceCode" id="cb3"><pre
class="sourceCode bash"><code class="sourceCode bash"><span id="cb3-1"><a href="#cb3-1" aria-hidden="true" tabindex="-1"></a><span class="fu">sudo</span> apt install docker.io docker-compose</span></code></pre></div>
<p>On Ubuntu 24.10, the <code>docker compose</code> v2 command can be
installed directly:</p>
<div class="sourceCode" id="cb4"><pre
class="sourceCode bash"><code class="sourceCode bash"><span id="cb4-1"><a href="#cb4-1" aria-hidden="true" tabindex="-1"></a><span class="fu">sudo</span> apt install docker.io docker-compose-v2</span></code></pre></div>
<p>On Rocky Linux 9, install <code>docker-ce</code> with
<code>docker compose</code> v2 commmand:</p>
<div class="sourceCode" id="cb5"><pre
class="sourceCode bash"><code class="sourceCode bash"><span id="cb5-1"><a href="#cb5-1" aria-hidden="true" tabindex="-1"></a><span class="fu">sudo</span> dnf config-manager <span class="at">--add-repo</span> https://download.docker.com/linux/rhel/docker-ce.repo</span>
<span id="cb5-2"><a href="#cb5-2" aria-hidden="true" tabindex="-1"></a><span class="fu">sudo</span> dnf <span class="at">-y</span> install docker-ce docker-ce-cli containerd.io docker-compose-plugin</span>
<span id="cb5-3"><a href="#cb5-3" aria-hidden="true" tabindex="-1"></a><span class="fu">sudo</span> systemctl <span class="at">--now</span> enable docker</span></code></pre></div>
<h2 id="various-other-tools">Various other tools</h2>
<p>We will use <code>netcat</code> (<code>netcat-traditional</code> on
Debian/Ubuntu), <code>jq</code>, <code>curl</code>,
<code>wireshark</code> (or <code>tcpdump</code>).</p>
<hr />
<!--config:
wrap: false
margins:
left: 10
right: 10
-->
<h1 id="local-machine-setup-22">Local Machine Setup (2/2)</h1>
<h2 id="docker-installation-on-macos">Docker Installation on MacOS</h2>
<p>The Docker containers used in this workshop can be built and run on
MacOS.</p>
<p>Install Docker using brew:</p>
<div class="sourceCode" id="cb6"><pre
class="sourceCode bash"><code class="sourceCode bash"><span id="cb6-1"><a href="#cb6-1" aria-hidden="true" tabindex="-1"></a><span class="ex">brew</span> install jq</span>
<span id="cb6-2"><a href="#cb6-2" aria-hidden="true" tabindex="-1"></a><span class="ex">brew</span> install <span class="at">--cask</span> docker</span></code></pre></div>
<p>But access can only be made through locally forwarded ports on
<em>localhost</em> (aka <em>127.0.0.1</em> or <em>::1</em>).</p>
<div class="sourceCode" id="cb7"><pre
class="sourceCode bash"><code class="sourceCode bash"><span id="cb7-1"><a href="#cb7-1" aria-hidden="true" tabindex="-1"></a><span class="fu">ssh</span> [email protected] <span class="at">-p</span> 8022</span></code></pre></div>
<p>instead of</p>
<div class="sourceCode" id="cb8"><pre
class="sourceCode bash"><code class="sourceCode bash"><span id="cb8-1"><a href="#cb8-1" aria-hidden="true" tabindex="-1"></a><span class="fu">ssh</span> [email protected]</span></code></pre></div>
<hr />
<!--config:
wrap: false
margins:
left: 10
right: 10
-->
<h1 id="labs-containers-12">Labs Containers (1/2)</h1>
<ul>
<li><p>2 containers will be used during this workshop, one for
<em>gateway</em> and a second for <em>internal</em></p></li>
<li><p>Build and start containers with:</p></li>
</ul>
<div class="sourceCode" id="cb9"><pre
class="sourceCode sshschema"><code class="sourceCode schematics"><span id="cb9-1"><a href="#cb9-1" aria-hidden="true" tabindex="-1"></a>(<span class="im">local</span>)$ cd docker</span>
<span id="cb9-2"><a href="#cb9-2" aria-hidden="true" tabindex="-1"></a>(<span class="im">local</span>)$ ./build_containers.sh</span>
<span id="cb9-3"><a href="#cb9-3" aria-hidden="true" tabindex="-1"></a>(<span class="im">local</span>)$ ./start_containers.sh</span></code></pre></div>
<ul>
<li>Print setup information:</li>
</ul>
<div class="sourceCode" id="cb10"><pre
class="sourceCode sshschema"><code class="sourceCode schematics"><span id="cb10-1"><a href="#cb10-1" aria-hidden="true" tabindex="-1"></a>(<span class="im">local</span>)$ ./get_info.sh</span></code></pre></div>
<ul>
<li>Stop containers with:</li>
</ul>
<div class="sourceCode" id="cb11"><pre
class="sourceCode sshschema"><code class="sourceCode schematics"><span id="cb11-1"><a href="#cb11-1" aria-hidden="true" tabindex="-1"></a>(<span class="im">local</span>)$ ./stop_containers.sh</span></code></pre></div>
<ul>
<li>Cleanup the whole Docker setup: <strong>WARNING this will remove all
containers, images and networks from your local Docker
setup</strong></li>
</ul>
<div class="sourceCode" id="cb12"><pre
class="sourceCode sshschema"><code class="sourceCode schematics"><span id="cb12-1"><a href="#cb12-1" aria-hidden="true" tabindex="-1"></a>(<span class="im">local</span>)$ ./docker_wipe.sh</span>
<span id="cb12-2"><a href="#cb12-2" aria-hidden="true" tabindex="-1"></a>(<span class="im">local</span>)$ sudo systemctl restart docker</span></code></pre></div>
<hr />
<!--config:
wrap: false
margins:
left: 10
right: 10
-->
<h1 id="labs-containers-22">Labs Containers (2/2)</h1>
<p>Pre-built versions of the containers (provided via USB drives or
Wi-Fi <em>http://192.168.178.2/</em>) can be loaded from the
<code>docker/images/</code> directory with the following command:</p>
<div class="sourceCode" id="cb13"><pre
class="sourceCode sshschema"><code class="sourceCode schematics"><span id="cb13-1"><a href="#cb13-1" aria-hidden="true" tabindex="-1"></a>(<span class="im">local</span>)$ cd docker</span>
<span id="cb13-2"><a href="#cb13-2" aria-hidden="true" tabindex="-1"></a>(<span class="im">local</span>)$ ./load_images.sh</span></code></pre></div>
<p>Locally built container images, can be exported to files in the
<code>docker/images/</code> directory with the following command:</p>
<div class="sourceCode" id="cb14"><pre
class="sourceCode sshschema"><code class="sourceCode schematics"><span id="cb14-1"><a href="#cb14-1" aria-hidden="true" tabindex="-1"></a>(<span class="im">local</span>)$ cd docker</span>
<span id="cb14-2"><a href="#cb14-2" aria-hidden="true" tabindex="-1"></a>(<span class="im">local</span>)$ ./save_images.sh</span></code></pre></div>
<p>Images downloaded from local webserver can be verified for integrity
with the following command:</p>
<div class="sourceCode" id="cb15"><pre
class="sourceCode sshschema"><code class="sourceCode schematics"><span id="cb15-1"><a href="#cb15-1" aria-hidden="true" tabindex="-1"></a>(<span class="im">local</span>)$ cd docker/images</span>
<span id="cb15-2"><a href="#cb15-2" aria-hidden="true" tabindex="-1"></a>(<span class="im">local</span>)$ sha256sum -c SHA256SUMS</span>
<span id="cb15-3"><a href="#cb15-3" aria-hidden="true" tabindex="-1"></a>docker-<span class="bu">gateway</span>.image: OK</span>
<span id="cb15-4"><a href="#cb15-4" aria-hidden="true" tabindex="-1"></a>docker-<span class="kw">internal</span>.image: OK</span></code></pre></div>
<hr />
<!--config:
wrap: false
margins:
left: 10
right: 10
-->
<h1 id="labs-network-layout">Labs Network Layout</h1>
<div class="sourceCode" id="cb16"><pre
class="sourceCode sshschema"><code class="sourceCode schematics"><span id="cb16-1"><a href="#cb16-1" aria-hidden="true" tabindex="-1"></a> ┌───────────────────┐ ┌───────────────────────────────────────────┐</span>
<span id="cb16-2"><a href="#cb16-2" aria-hidden="true" tabindex="-1"></a> │ Local Network │ │ Lab network (containers) │</span>
<span id="cb16-3"><a href="#cb16-3" aria-hidden="true" tabindex="-1"></a> │ ┌───────────────┐ │ │ ┌─────────────┐ ┌──────────────┐ │</span>
<span id="cb16-4"><a href="#cb16-4" aria-hidden="true" tabindex="-1"></a> │ │ <span class="im">local</span> │ │<------------>│ │ <span class="bu">gateway</span> │ │ <span class="kw">internal</span> │ │</span>
<span id="cb16-5"><a href="#cb16-5" aria-hidden="true" tabindex="-1"></a> │ └───────────────┘ │ <span class="bu">The_Internet</span> │ └─────────────┘ └──────────────┘ │</span>
<span id="cb16-6"><a href="#cb16-6" aria-hidden="true" tabindex="-1"></a> │ IP: 172.18.0.1 │ │ Pub 172.18.0.2 │</span>
<span id="cb16-7"><a href="#cb16-7" aria-hidden="true" tabindex="-1"></a> │ │ │ Priv 172.19.0.2 <-<span class="kw">LAN</span>-> Priv 172.19.0.3 │</span>
<span id="cb16-8"><a href="#cb16-8" aria-hidden="true" tabindex="-1"></a> └───────────────────┘ └───────────────────────────────────────────┘</span></code></pre></div>
<p>(IP addresses may differ from your Docker setup)</p>
<p>Your <em>local</em> machine can reach <code>gateway</code> server
over ‘The Internet’</p>
<ul>
<li><p><em>local</em> machine is your personal laptop or VM. It is
located “somewhere on the Internet” It is able to reach
<code>gateway</code> on TCP port 22 (on 172.18.0.2)</p></li>
<li><p><strong>Lab network</strong> is a remote private LAN
(172.19.0.0/16 in this case)</p></li>
<li><p>On this remote LAN, <code>gateway</code> is privately known as
172.19.0.2.</p></li>
<li><p><code>gateway</code> is connected to another machine named
<strong>internal</strong> (172.19.0.3)</p></li>
</ul>
<hr />
<!--config:
margins:
left: 10
right: 10
-->
<h1 id="usernames-and-passwords">Usernames and Passwords</h1>
<p>2 users exist on each container: <em>root</em> and <em>user</em>.</p>
<p>Passwords are the same as usernames. <em>user</em> has
<strong>sudo</strong> access on each machine (no password required).</p>
<h1 id="shell-commands">Shell commands</h1>
<p>Shell commands are prefixed by a prompt designating the machine on
which the command shall be run:</p>
<div class="sourceCode" id="cb17"><pre
class="sourceCode sshschema"><code class="sourceCode schematics"><span id="cb17-1"><a href="#cb17-1" aria-hidden="true" tabindex="-1"></a>(<span class="im">local</span>)$ <<span class="im">local</span> command></span>
<span id="cb17-2"><a href="#cb17-2" aria-hidden="true" tabindex="-1"></a>(<span class="bu">gateway</span>)$ <remote command on <span class="bu">gateway</span> machine></span>
<span id="cb17-3"><a href="#cb17-3" aria-hidden="true" tabindex="-1"></a>(<span class="kw">internal</span>)$ <remote command on <span class="kw">internal</span> machine></span></code></pre></div>
<h1 id="ip-addresses">IP addresses</h1>
<ul>
<li><p>IP addresses are configured statically when you execute
<code>start_containers.sh</code></p></li>
<li><p>3 IP addresses will appear during this workshop</p>
<ul>
<li><gateway_pub></li>
<li><gateway_priv></li>
<li><internal_priv></li>
</ul></li>
</ul>
<hr />
<!--config:
margins:
left: 10
right: 10
-->
<h1 id="illustration-telnet-is-not-secure">Illustration: Telnet is not
secure</h1>
<ul>
<li><p>A <em>telnet</em> server is listening on <em>gateway</em>, TCP
port 23</p></li>
<li><p>Start a traffic capture on TCP port 23 in another
terminal:</p></li>
</ul>
<div class="sourceCode" id="cb18"><pre
class="sourceCode sshschema"><code class="sourceCode schematics"><span id="cb18-1"><a href="#cb18-1" aria-hidden="true" tabindex="-1"></a>(<span class="im">local</span>)$ sudo apt install wireshark</span>
<span id="cb18-2"><a href="#cb18-2" aria-hidden="true" tabindex="-1"></a>(<span class="im">local</span>)$ sudo wireshark</span></code></pre></div>
<ul>
<li>Start a capture on your main network interface (<em>eth0</em>) or
<em>any</em></li>
<li>Then, in another shell, run the <em>telnet</em> client on your local
machine:</li>
</ul>
<div class="sourceCode" id="cb19"><pre
class="sourceCode sshschema"><code class="sourceCode schematics"><span id="cb19-1"><a href="#cb19-1" aria-hidden="true" tabindex="-1"></a>(<span class="im">local</span>)$ sudo apt install telnet</span>
<span id="cb19-2"><a href="#cb19-2" aria-hidden="true" tabindex="-1"></a>(<span class="im">local</span>)$ telnet 172.18.0.2</span></code></pre></div>
<ul>
<li><p>Login, <em>user</em> Password, <em>user</em></p></li>
<li><p>Finally, right-click on the first TCP packet that belongs to this
connection (port 23), then <em>Follow</em> -> <em>TCP
Stream</em></p></li>
</ul>
<hr />
<!--config:
margins:
left: 10
right: 10
-->
<h1 id="two-main-issues">Two main issues:</h1>
<ul>
<li><p>Cleartext message exchange: vulnerable to traffic sniffing
tcpdump/wireshark on traffic path (firewall, router)</p></li>
<li><p>Insecure authentication: vulnerable to Man-In-The-Middle attack
Ettercap (another machine on same LAN), proxy software on an
intermediate router/firewall</p></li>
</ul>
<p>Same goes for FTP, HTTP, SMTP, …</p>
<hr />
<!--config:
margins:
left: 10
right: 10
-->
<h1 id="ssh-history-implementations">SSH History &
Implementations</h1>
<p>SSH stands for <strong>S</strong>ecure <strong>SH</strong>ell</p>
<h2 id="protocol-versions">Protocol Versions</h2>
<ul>
<li><a
href="https://en.wikipedia.org/wiki/Secure_Shell#Version_1">SSH-1.0</a>
1995, by Tatu Ylönen, researcher at Helsinki University of
Technology</li>
<li><a href="https://datatracker.ietf.org/doc/html/rfc4254">SSH-2.0</a>
2006, IETF Standardization RFC 4251-4256</li>
<li><a
href="https://datatracker.ietf.org/doc/html/rfc4253#section-5.1">SSH-1.99</a>
Retro-compatibility pseudo-version, Old client/New Server</li>
<li><a href="https://github.com/francoismichel/ssh3">SSH3</a> (?)
Experimental implementation using HTTP/3 (QUIC)</li>
</ul>
<h2 id="implementations">Implementations</h2>
<ul>
<li>OpenSSH on Unices, Client & Server for GNU/Linux, *BSD, MacOS,
…</li>
<li>OpenSSH on MS Windows</li>
<li>Terminal & File transfer clients for MS Windows: PuTTY,
MobaXterm, WinSCP, FileZilla, …</li>
<li>Dropbear, Lightweight implementation, for embedded-type Linux (or
other Unices) systems</li>
<li>On mobile: ConnectBot for Android, Termius for Apple iOS</li>
<li>Network Appliances, OpenSSH or custom implementation</li>
</ul>
<hr />
<!--config:
margins:
left: 10
right: 10
-->
<h1 id="focus-on-openssh-tool-suite-on-gnulinux">Focus on OpenSSH Tool
suite (on GNU/Linux)</h1>
<ul>
<li>Focus on the OpenSSH tool suite, a project started in 1999</li>
<li>Clients & Server software</li>
<li>This is the reference opensource version for many OSes</li>
<li>It is based on modern cryptography algorithms and protocols</li>
<li>It is widely available out-of-the-box</li>
<li>It contains a wide range of tools (remote shell, file transfer, key
management, …)</li>
<li>Automation friendly (Ansible, or custom scripts)</li>
<li>Main tools
<ul>
<li><em>ssh</em> - Remote terminal access</li>
<li><em>scp</em> - File transfer</li>
<li><em>sftp</em> - FTP-like file transfer</li>
</ul></li>
<li>Helpers
<ul>
<li><em>ssh-keygen</em> - Public/Private keypair generation</li>
<li><em>ssh-copy-id</em> - Key deployment script</li>
<li><em>ssh-agent</em> - Key management daemon (equivalent to PuTTY’s
pageant.exe)</li>
<li><em>ssh-add</em> - Key/Agent management tool</li>
</ul></li>
</ul>
<hr />
<!--config:
margins:
left: 10
right: 10
-->
<h1 id="documentation">Documentation</h1>
<p>Online manual pages</p>
<ul>
<li><p>Listing of <strong>C</strong>ommand <strong>LI</strong>ne man
pages:</p>
<p><code>$ man -k ssh</code></p></li>
<li><p>Listing client’s configuration options:</p>
<p><code>$ man ssh_config</code></p></li>
<li><p>Listing server’s configuration options (the
<em>openssh-server</em> package must be installed):</p>
<p><code>$ man sshd_config</code></p></li>
<li><p>CLI help, in your terminal, just type</p>
<ul>
<li><code>ssh</code> for the client</li>
<li><code>/usr/sbin/sshd --help</code> for the server</li>
<li><code>ssh-keygen --help</code> for the key management tool</li>
<li>…</li>
</ul></li>
</ul>
<hr />
<!--config:
margins:
left: 10
right: 10
-->
<h1 id="first-login-12---commands-tcpdump-fingerprints">First Login
(1/2) - Commands, tcpdump & fingerprints</h1>
<p>Syntax is: <code>ssh <username>@<host></code>, where
<em><host></em> can be a hostname or an IP address</p>
<p>Username and password are the same as the one from the telnet
example: - Username: <em>user</em> / Password: <em>user</em></p>
<ul>
<li>Start a traffic capture on TCP port 22 in another terminal, traffic
is <strong>encrypted</strong>:</li>
</ul>
<div class="sourceCode" id="cb20"><pre
class="sourceCode sshschema"><code class="sourceCode schematics"><span id="cb20-1"><a href="#cb20-1" aria-hidden="true" tabindex="-1"></a>(<span class="im">local</span>)$ sudo tcpdump -n -i any -XXX tcp and port 22</span></code></pre></div>
<ul>
<li><p>Retrieve the server keys fingerprints through a secure
channel:</p>
<p><strong>https://github.com/wllm-rbnt/uybhys-2024-openssh-workshop/blob/main/fingerprints.txt</strong></p></li>
</ul>
<hr />
<!--config:
margins:
left: 10
right: 10
-->
<h1 id="first-login-22---connection-host-authentication">First Login
(2/2) - Connection & host authentication</h1>
<p>Type the following in a local terminal on your machine:</p>
<div class="sourceCode" id="cb21"><pre
class="sourceCode sshschema"><code class="sourceCode schematics"><span id="cb21-1"><a href="#cb21-1" aria-hidden="true" tabindex="-1"></a>(<span class="im">local</span>)$ ssh user@<<span class="bu">gateway_pub</span>></span>
<span id="cb21-2"><a href="#cb21-2" aria-hidden="true" tabindex="-1"></a>or</span>
<span id="cb21-3"><a href="#cb21-3" aria-hidden="true" tabindex="-1"></a>(<span class="im">local</span>)$ ssh -o VisualHostKey=true user@<<span class="bu">gateway_pub</span>></span>
<span id="cb21-4"><a href="#cb21-4" aria-hidden="true" tabindex="-1"></a>The authenticity of host '172.18.0.2 (172.18.0.2)' can't be established.</span>
<span id="cb21-5"><a href="#cb21-5" aria-hidden="true" tabindex="-1"></a>ED25519 key fingerprint is SHA256:HFofTLfh2W/1IR3+g0sXGAcRs4ZnVsWwGKmbOzeMefk.</span>
<span id="cb21-6"><a href="#cb21-6" aria-hidden="true" tabindex="-1"></a>+--[ED25519 256]--+</span>
<span id="cb21-7"><a href="#cb21-7" aria-hidden="true" tabindex="-1"></a>| . +B=*o|</span>
<span id="cb21-8"><a href="#cb21-8" aria-hidden="true" tabindex="-1"></a>| o ooBX.o|</span>
<span id="cb21-9"><a href="#cb21-9" aria-hidden="true" tabindex="-1"></a>| o oo=Oo=.|</span>
<span id="cb21-10"><a href="#cb21-10" aria-hidden="true" tabindex="-1"></a>| + o..= o.*|</span>
<span id="cb21-11"><a href="#cb21-11" aria-hidden="true" tabindex="-1"></a>| . S .o o o=|</span>
<span id="cb21-12"><a href="#cb21-12" aria-hidden="true" tabindex="-1"></a>| o . o..|</span>
<span id="cb21-13"><a href="#cb21-13" aria-hidden="true" tabindex="-1"></a>| = o |</span>
<span id="cb21-14"><a href="#cb21-14" aria-hidden="true" tabindex="-1"></a>| = * |</span>
<span id="cb21-15"><a href="#cb21-15" aria-hidden="true" tabindex="-1"></a>| + oE |</span>
<span id="cb21-16"><a href="#cb21-16" aria-hidden="true" tabindex="-1"></a>+----[SHA256]-----+</span>
<span id="cb21-17"><a href="#cb21-17" aria-hidden="true" tabindex="-1"></a>This key is not known by any other names.</span>
<span id="cb21-18"><a href="#cb21-18" aria-hidden="true" tabindex="-1"></a>Are you sure you want to continue connecting (yes/no/[fingerprint])?</span></code></pre></div>
<ul>
<li>Type <em>yes</em> to accept and go on with user authentication, or
<em>no</em> to refuse and disconnect immediately</li>
<li>or type the <em>fingerprint</em> you received from the secure
channel If the fingerprint you entered matches the one that is printed,
the system will proceed with user authentication</li>
</ul>
<hr />
<!--config:
margins:
left: 10
right: 10
-->
<h1 id="known-hosts-fingerprint-databases">Known hosts fingerprint
databases</h1>
<p>Remote Host Authentication is performed only on first connection</p>
<p><code>~/.ssh/known_hosts</code> is then populated with host reference
and corresponding key fingerprint</p>
<p><code>/etc/ssh/ssh_known_hosts</code> can be used as a system-wide
database of know hosts</p>
<p>Hosts references can be stored as clear text (IP or hostname) or the
corresponding hash (see <em>HashKnownHosts</em> option)</p>
<h1 id="host-keys-location-on-openssh-server">Host keys location on
OpenSSH server</h1>
<div class="sourceCode" id="cb22"><pre
class="sourceCode sshschema"><code class="sourceCode schematics"><span id="cb22-1"><a href="#cb22-1" aria-hidden="true" tabindex="-1"></a>(<span class="bu">gateway</span>)$ ls -l /etc/ssh/ssh_host*pub</span>
<span id="cb22-2"><a href="#cb22-2" aria-hidden="true" tabindex="-1"></a>-rw------- 1 root root 513 May 23 12:39 /etc/ssh/ssh_host_ecdsa_key</span>
<span id="cb22-3"><a href="#cb22-3" aria-hidden="true" tabindex="-1"></a>-rw-r--r-- 1 root root 179 May 23 12:39 /etc/ssh/ssh_host_ecdsa_key.pub</span>
<span id="cb22-4"><a href="#cb22-4" aria-hidden="true" tabindex="-1"></a>-rw------- 1 root root 411 May 23 12:39 /etc/ssh/ssh_host_ed25519_key</span>
<span id="cb22-5"><a href="#cb22-5" aria-hidden="true" tabindex="-1"></a>-rw-r--r-- 1 root root 99 May 23 12:39 /etc/ssh/ssh_host_ed25519_key.pub</span>
<span id="cb22-6"><a href="#cb22-6" aria-hidden="true" tabindex="-1"></a>-rw------- 1 root root 2602 May 23 12:39 /etc/ssh/ssh_host_rsa_key</span>
<span id="cb22-7"><a href="#cb22-7" aria-hidden="true" tabindex="-1"></a>-rw-r--r-- 1 root root 571 May 23 12:39 /etc/ssh/ssh_host_rsa_key.pub</span></code></pre></div>
<h1 id="computing-fingerprints-of-host-keys">Computing fingerprints of
host keys</h1>
<div class="sourceCode" id="cb23"><pre
class="sourceCode sshschema"><code class="sourceCode schematics"><span id="cb23-1"><a href="#cb23-1" aria-hidden="true" tabindex="-1"></a>(<span class="bu">gateway</span>)$ for i in $(ls -1 /etc/ssh/ssh_host*pub); do ssh-keygen -lf $i; done</span>
<span id="cb23-2"><a href="#cb23-2" aria-hidden="true" tabindex="-1"></a>256 SHA256:gbF30TEqv4ucpI3VFIEjq0dnrji5woxacnPe+N9mFX8 root@460a6cac3a3c (ECDSA)</span>
<span id="cb23-3"><a href="#cb23-3" aria-hidden="true" tabindex="-1"></a>256 SHA256:/hUAOroJsQzhM4f9qSZxcBLqEYqmoPi03pVX2fQUxrg root@460a6cac3a3c (ED25519)</span>
<span id="cb23-4"><a href="#cb23-4" aria-hidden="true" tabindex="-1"></a>3072 SHA256:D0gvg+2kFzvrLjqi0OEZ23tnQN3H/+oB3cqm0VZHWiQ root@460a6cac3a3c (RSA)</span></code></pre></div>
<p>Note: use <code>ssh-keygen -lvf <public_key_file></code> to
generate the visual ASCII art representation of a key</p>
<hr />
<!--config:
margins:
left: 10
right: 10
-->
<h1 id="configuration-12">Configuration (1/2)</h1>
<h2 id="configuration-files">Configuration files</h2>
<p>Client:</p>
<ul>
<li>Command line arguments</li>
<li>Per-user client configuration: <code>~/.ssh/config</code></li>
<li>System-wide local configuration:
<code>/etc/ssh/ssh_config.d/*</code></li>
<li>System-wide client configuration:
<code>/etc/ssh/ssh_config</code></li>
</ul>
<p>Server:</p>
<ul>
<li>Server local configuration:
<code>/etc/ssh/sshd_config.d/*</code></li>
<li>Server configuration: <code>/etc/ssh/sshd_config</code></li>
</ul>
<h2 id="configuration-options">Configuration options</h2>
<ul>
<li>Client configuration options: <code>$ man ssh_config</code></li>
<li>Server configuration options: <code>$ man sshd_config</code></li>
</ul>
<hr />
<!--config:
margins:
left: 10
right: 10
-->
<h1 id="configuration-22---per-host-client-configuration">Configuration
(2/2) - Per host client configuration</h1>
<p>Client configuration options can be specified per host</p>
<p>Example:</p>
<p>Type following in your local <code>~/.ssh/config</code>:</p>
<div class="sourceCode" id="cb24"><pre
class="sourceCode sshschema"><code class="sourceCode schematics"><span id="cb24-1"><a href="#cb24-1" aria-hidden="true" tabindex="-1"></a>Host <span class="bu">gateway</span></span>
<span id="cb24-2"><a href="#cb24-2" aria-hidden="true" tabindex="-1"></a> Hostname <<span class="bu">gateway_pub</span>></span>
<span id="cb24-3"><a href="#cb24-3" aria-hidden="true" tabindex="-1"></a> User user</span></code></pre></div>
<p>Tips: Printing the “would be applied” configuration</p>
<p>The <code>-G</code> parameter cause <code>ssh</code> to print the
configuration that would be applied for a given connection (without
actually connecting)</p>
<div class="sourceCode" id="cb25"><pre
class="sourceCode sshschema"><code class="sourceCode schematics"><span id="cb25-1"><a href="#cb25-1" aria-hidden="true" tabindex="-1"></a>(<span class="im">local</span>)$ ssh -G <span class="bu">gateway</span></span></code></pre></div>
<p>The following command should output your username:</p>
<div class="sourceCode" id="cb26"><pre
class="sourceCode sshschema"><code class="sourceCode schematics"><span id="cb26-1"><a href="#cb26-1" aria-hidden="true" tabindex="-1"></a>(<span class="im">local</span>)$ ssh -G <span class="bu">gateway</span> | grep user</span>
<span id="cb26-2"><a href="#cb26-2" aria-hidden="true" tabindex="-1"></a>user user</span></code></pre></div>
<hr />
<!--config:
margins:
left: 10
right: 10
-->
<h1 id="tips">Tips</h1>
<h2 id="increase-verbosity">Increase verbosity</h2>
<p>Launch ssh commands with -v parameter in order to increase verbosity,
and help with debugging</p>
<p>Example:</p>
<div class="sourceCode" id="cb27"><pre
class="sourceCode sshschema"><code class="sourceCode schematics"><span id="cb27-1"><a href="#cb27-1" aria-hidden="true" tabindex="-1"></a>(<span class="im">local</span>)$ ssh -v user@<<span class="bu">gateway_pub</span>></span>
<span id="cb27-2"><a href="#cb27-2" aria-hidden="true" tabindex="-1"></a>OpenSSH_8.4p1 Debian-5+deb11u2, OpenSSL 1.1.1w 11 Sep 2023</span>
<span id="cb27-3"><a href="#cb27-3" aria-hidden="true" tabindex="-1"></a>debug1: Reading configuration data /home/user/.ssh/config</span>
<span id="cb27-4"><a href="#cb27-4" aria-hidden="true" tabindex="-1"></a>debug1: Reading configuration data /etc/ssh/ssh_config</span>
<span id="cb27-5"><a href="#cb27-5" aria-hidden="true" tabindex="-1"></a>[...]</span></code></pre></div>
<h2 id="escape-character">Escape character</h2>
<p>The escape character can be used to pass out-of-band commands to ssh
client</p>
<ul>
<li>By default <code>~</code>, must be at beginning of a new line</li>
<li>Commands:
<ul>
<li>Quit current session <code>~.</code></li>
<li>List Forwarded connections <code>~#</code></li>
<li>Decrease the verbosity (LogLevel) <code>~V</code></li>
<li>Increase the verbosity (LogLevel) <code>~v</code></li>
</ul></li>
<li>Repeat <code>~</code> char in order to type it ( <code>~~</code>
)</li>
</ul>
<hr />
<!--config:
margins:
left: 10
right: 10
-->
<h1 id="public-key-authentication-12">Public Key Authentication
(1/2)</h1>
<h2 id="main-authentication-methods">Main Authentication Methods</h2>
<ul>
<li><em>Password</em> authentication</li>
<li><em>Public/Private key</em> authentication
<ul>
<li>Used for password-less authentication (passphrase may be required to
unlock private key)</li>
</ul></li>
</ul>
<h2 id="lab">Lab</h2>
<ul>
<li>Generate a new key pair on your local system (with or without a
passphrase):</li>
</ul>
<div class="sourceCode" id="cb28"><pre
class="sourceCode sshschema"><code class="sourceCode schematics"><span id="cb28-1"><a href="#cb28-1" aria-hidden="true" tabindex="-1"></a>(<span class="im">local</span>)$ ssh-keygen -f ~/.ssh/my-ssh-key</span></code></pre></div>
<ul>
<li>Install your public key on the remote server:</li>
</ul>
<div class="sourceCode" id="cb29"><pre
class="sourceCode sshschema"><code class="sourceCode schematics"><span id="cb29-1"><a href="#cb29-1" aria-hidden="true" tabindex="-1"></a>(<span class="im">local</span>)$ ssh-copy-id -i ~/.ssh/my-ssh-key.pub user@<<span class="bu">gateway_pub</span>></span></code></pre></div>
<p><strong>Note</strong>: <code>ssh-copy-id</code> copies the public key
from <code>~/.ssh/my-ssh-key.pub</code> to the remote machine in
<code>~/.ssh/authorized_keys</code></p>
<hr />
<!--config:
margins:
left: 10
right: 10
-->
<h1 id="public-key-authentication-22">Public Key Authentication
(2/2)</h1>
<ul>
<li>Login again with your new key pair:</li>
</ul>
<div class="sourceCode" id="cb30"><pre
class="sourceCode sshschema"><code class="sourceCode schematics"><span id="cb30-1"><a href="#cb30-1" aria-hidden="true" tabindex="-1"></a>(<span class="im">local</span>)$ ssh -i ~/.ssh/my-ssh-key user@<<span class="bu">gateway_pub</span>></span></code></pre></div>
<ul>
<li>Reference your key pair in your personal local configuration file
(<code>~/.ssh/config</code>):</li>
</ul>
<div class="sourceCode" id="cb31"><pre
class="sourceCode sshschema"><code class="sourceCode schematics"><span id="cb31-1"><a href="#cb31-1" aria-hidden="true" tabindex="-1"></a>Host <span class="bu">gateway</span></span>
<span id="cb31-2"><a href="#cb31-2" aria-hidden="true" tabindex="-1"></a> Hostname <<span class="bu">gateway_pub</span>></span>
<span id="cb31-3"><a href="#cb31-3" aria-hidden="true" tabindex="-1"></a> User user</span>
<span id="cb31-4"><a href="#cb31-4" aria-hidden="true" tabindex="-1"></a> IdentityFile ~/.ssh/my-ssh-key</span></code></pre></div>
<hr />
<!--config:
margins:
left: 10
right: 10
-->
<h1 id="authentication-agent-13">Authentication Agent (1/3)</h1>
<p>The Authentication Agent can hold access to private keys, thus
eliminating the need to enter passphrase at each use</p>
<p>Start the agent:</p>
<div class="sourceCode" id="cb32"><pre
class="sourceCode sshschema"><code class="sourceCode schematics"><span id="cb32-1"><a href="#cb32-1" aria-hidden="true" tabindex="-1"></a>(<span class="im">local</span>)$ ssh-agent | tee ssh-agent-env.sh</span>
<span id="cb32-2"><a href="#cb32-2" aria-hidden="true" tabindex="-1"></a>SSH_AUTH_SOCK=/tmp/ssh-KwTcl7ZieUKD/agent.1193973; export SSH_AUTH_SOCK;</span>
<span id="cb32-3"><a href="#cb32-3" aria-hidden="true" tabindex="-1"></a>SSH_AGENT_PID=1193974; export SSH_AGENT_PID;</span>
<span id="cb32-4"><a href="#cb32-4" aria-hidden="true" tabindex="-1"></a>echo Agent pid 1193974;</span>
<span id="cb32-5"><a href="#cb32-5" aria-hidden="true" tabindex="-1"></a>(<span class="im">local</span>)$ source ssh-agent-env.sh</span>
<span id="cb32-6"><a href="#cb32-6" aria-hidden="true" tabindex="-1"></a>Agent pid 1193974</span></code></pre></div>
<hr />
<!--config:
margins:
left: 10
right: 10
-->
<h1 id="authentication-agent-23">Authentication Agent (2/3)</h1>
<p>Load private key into the agent:</p>
<div class="sourceCode" id="cb33"><pre
class="sourceCode sshschema"><code class="sourceCode schematics"><span id="cb33-1"><a href="#cb33-1" aria-hidden="true" tabindex="-1"></a>(<span class="im">local</span>)$ ssh-add ~/.ssh/my-ssh-key</span>
<span id="cb33-2"><a href="#cb33-2" aria-hidden="true" tabindex="-1"></a>Enter passphrase for /home/user/.ssh/my-ssh-key: ********</span>
<span id="cb33-3"><a href="#cb33-3" aria-hidden="true" tabindex="-1"></a>Identity added: my-ssh-key (user@local)</span></code></pre></div>
<p>Connect to remote machine:</p>
<div class="sourceCode" id="cb34"><pre
class="sourceCode sshschema"><code class="sourceCode schematics"><span id="cb34-1"><a href="#cb34-1" aria-hidden="true" tabindex="-1"></a>(<span class="im">local</span>)$ ssh user@<<span class="bu">gateway_pub</span>></span></code></pre></div>
<hr />
<!--config:
margins:
left: 10
right: 10
-->
<h1 id="authentication-agent-33">Authentication Agent (3/3)</h1>
<h2 id="keychain">Keychain</h2>
<p>Going further, <a
href="https://www.funtoo.org/Funtoo:Keychain">keychain</a> can be used
to manage ssh-agent & keys across logins sessions.</p>
<p>Install <code>keychain</code>:</p>
<div class="sourceCode" id="cb35"><pre
class="sourceCode sshschema"><code class="sourceCode schematics"><span id="cb35-1"><a href="#cb35-1" aria-hidden="true" tabindex="-1"></a>(<span class="im">local</span>)$ apt install keychain</span></code></pre></div>
<p>Add the following to your <code>~/.bashrc</code> or
<code>~/.zshrc</code>:</p>
<div class="sourceCode" id="cb36"><pre
class="sourceCode sshschema"><code class="sourceCode schematics"><span id="cb36-1"><a href="#cb36-1" aria-hidden="true" tabindex="-1"></a>keychain --dir ~/.keychain --agents "ssh" -q ~/.ssh/my-ssh-key</span></code></pre></div>
<p>Now, each new shell session will inherit <code>ssh-agent</code>
environment variables corresponding to the running agent.</p>
<hr />
<!--config:
margins:
left: 10
right: 10
-->
<h1 id="remote-command-execution-12">Remote Command Execution (1/2)</h1>
<p>Simple command execution:</p>
<div class="sourceCode" id="cb37"><pre
class="sourceCode sshschema"><code class="sourceCode schematics"><span id="cb37-1"><a href="#cb37-1" aria-hidden="true" tabindex="-1"></a>(<span class="im">local</span>)$ ssh user@<<span class="bu">gateway_pub</span>> hostname</span></code></pre></div>
<p>With redirection to local file:</p>
<div class="sourceCode" id="cb38"><pre
class="sourceCode sshschema"><code class="sourceCode schematics"><span id="cb38-1"><a href="#cb38-1" aria-hidden="true" tabindex="-1"></a>(<span class="im">local</span>)$ ssh user@<<span class="bu">gateway_pub</span>> hostname > hostname.txt</span></code></pre></div>
<hr />
<!--config:
margins:
left: 10
right: 10
-->
<h1 id="remote-command-execution-22">Remote Command Execution (2/2)</h1>
<p>With redirection to remote file:</p>
<div class="sourceCode" id="cb39"><pre
class="sourceCode sshschema"><code class="sourceCode schematics"><span id="cb39-1"><a href="#cb39-1" aria-hidden="true" tabindex="-1"></a>(<span class="im">local</span>)$ ssh user@<<span class="bu">gateway_pub</span>> "hostname > hostname.txt"</span></code></pre></div>
<p>With pipes:</p>
<div class="sourceCode" id="cb40"><pre
class="sourceCode sshschema"><code class="sourceCode schematics"><span id="cb40-1"><a href="#cb40-1" aria-hidden="true" tabindex="-1"></a>(<span class="im">local</span>)$ echo blabla | ssh user@<<span class="bu">gateway_pub</span>> "cat - | tr 'a-z' 'A-Z'"</span></code></pre></div>
<hr />
<!--config:
margins:
left: 10
right: 10
-->
<h1 id="jumphost-12">Jumphost (1/2)</h1>
<p>A Jump Host is a machine used as a relay to reach another, otherwise
possibly unreachable, machine. This unreachable machine is named
internal-machine</p>
<div class="sourceCode" id="cb41"><pre
class="sourceCode sshschema"><code class="sourceCode schematics"><span id="cb41-1"><a href="#cb41-1" aria-hidden="true" tabindex="-1"></a> ┌────────────────────┐ ┌───────────────────────────────────────────────┐</span>
<span id="cb41-2"><a href="#cb41-2" aria-hidden="true" tabindex="-1"></a> │ <span class="bu">Internet</span> │ │ Internal network │</span>
<span id="cb41-3"><a href="#cb41-3" aria-hidden="true" tabindex="-1"></a> │ │ │ │</span>
<span id="cb41-4"><a href="#cb41-4" aria-hidden="true" tabindex="-1"></a> │ ┌───────────────┐ │ │ ┌─────────────┐ ┌──────────────────┐ │</span>
<span id="cb41-5"><a href="#cb41-5" aria-hidden="true" tabindex="-1"></a> │ │ <span class="im">local</span> ├──┼──────┤►│ <span class="bu">gateway</span> ├─────────►│ <span class="kw">internal</span> │ │</span>
<span id="cb41-6"><a href="#cb41-6" aria-hidden="true" tabindex="-1"></a> │ └───────────────┘ │ │ └─────────────┘ └──────────────────┘ │</span>
<span id="cb41-7"><a href="#cb41-7" aria-hidden="true" tabindex="-1"></a> │ │ │ used as jumphost unreachable to │ </span>
<span id="cb41-8"><a href="#cb41-8" aria-hidden="true" tabindex="-1"></a> │ │ │ the outside world │</span>
<span id="cb41-9"><a href="#cb41-9" aria-hidden="true" tabindex="-1"></a> └────────────────────┘ └───────────────────────────────────────────────┘</span></code></pre></div>
<p><em>Lab objective</em>: Connect to <em>internal</em> from your local
machine via SSH with a single command</p>
<hr />
<!--config:
margins:
left: 10
right: 10
-->
<h1 id="jumphost-22">Jumphost (2/2)</h1>
<p>Lab setup:</p>
<ul>
<li>First, copy your public key to the remote server (gateway):</li>
</ul>
<div class="sourceCode" id="cb42"><pre
class="sourceCode sshschema"><code class="sourceCode schematics"><span id="cb42-1"><a href="#cb42-1" aria-hidden="true" tabindex="-1"></a>(<span class="im">local</span>)$ scp .ssh/my-ssh-key.pub user@<<span class="bu">gateway_pub</span>>:</span></code></pre></div>
<ul>
<li>Login to the remote server then copy your public key to the
destination machine:</li>
</ul>
<div class="sourceCode" id="cb43"><pre
class="sourceCode sshschema"><code class="sourceCode schematics"><span id="cb43-1"><a href="#cb43-1" aria-hidden="true" tabindex="-1"></a>(<span class="im">local</span>)$ ssh user@<<span class="bu">gateway_pub</span>></span>
<span id="cb43-2"><a href="#cb43-2" aria-hidden="true" tabindex="-1"></a>(<span class="bu">gateway</span>)$ ssh-copy-id -f -i my-ssh-key.pub <<span class="kw">internal_priv</span>></span></code></pre></div>
<ul>
<li>Connect to the remote machine with a single command:</li>
</ul>
<div class="sourceCode" id="cb44"><pre
class="sourceCode sshschema"><code class="sourceCode schematics"><span id="cb44-1"><a href="#cb44-1" aria-hidden="true" tabindex="-1"></a>(<span class="im">local</span>)$ ssh -J user@<<span class="bu">gateway_pub</span>> user@<<span class="kw">internal_priv</span>></span></code></pre></div>
<p><strong>Note</strong>: <em>internal</em> host key fingerprints
available at
<strong>https://github.com/wllm-rbnt/uybhys-2024-openssh-workshop/blob/main/fingerprints.txt</strong></p>
<hr />
<!--config:
margins:
left: 10
right: 10
-->
<h1 id="socks-proxy-12">SOCKS proxy (1/2)</h1>
<p>A <em>SOCKS server</em> proxies TCP connections to arbitrary IP
addresses and ports</p>