-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path5-ssh-key.sh
More file actions
861 lines (645 loc) · 21.5 KB
/
5-ssh-key.sh
File metadata and controls
861 lines (645 loc) · 21.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
#!/bin/sh
. .lib/shell-compat-test.sh
_DURATION=10
_LSN_VERSION=1.0.3
# Put tutorial library files into $PATH if they are not already added
if [[ -d "$PWD/.lib" && ":$PATH:" != *":$PWD/.lib:"* ]]; then
PATH=$PWD/.lib:$PATH
fi
source ansi-terminal-ctl.sh
source progress.sh
source ssh-connection-test.sh
if [[ -n $_TUTR ]]; then
source editors+viewers.sh
source generic-error.sh
source open.sh
source platform.sh
public() { (( $# == 0 )) && echo $(grn public) || echo $(grn $*) ; }
private() { (( $# == 0 )) && echo $(red private) || echo $(red $*); }
username() { (( $# == 0 )) && echo $(mgn username) || echo $(mgn $*) ; }
password() { (( $# == 0 )) && echo $(ylw password) || echo $(ylw $*); }
_team() { (( $# == 0 )) && echo $(mgn The GAS Team) || echo $(mgn $*) ; }
fi
# TODO: rewrite this lesson to prefer an ED25519 key (if possible)
# macOS defaults to RSA b/c of an older version of OpenSSH
_KEYSIZE=2048
_ssh_key_is_already_installed_msg() {
cat <<-MSG
${_Y} _
${_Y} / )
${_Y} .' /
${_Y}---' (____ ${_Z}Your SSH key is already installed on GitHub.
${_Y} _)
${_Y} __) ${_Z}You are good to go!
${_Y} __)
${_Y}---.______)
${_Y}
MSG
_tutr_pressenter
}
_ssh_key_exists_msg() {
cat <<-MSG
I found an SSH key named $(path $(basename $1)) under $(path ~/.ssh).
* If you proceed with the lesson, you will skip over the step that
creates a new SSH key.
* If you would like to re-generate your SSH key under the tutorial's
guidance, exit this lesson, delete these files and start over again:
$(path $1)
$(path $1.pub)
MSG
_tutr_pressenter
}
# There are four ways connecting to GitHub could fail
# 0. No internet|host key verification failed = fix the problem and try again
# 1. No local SSH keys = create and upload new key to GitHub
# 2. Local SSH key is not on GitHub = don't re-create, but upload to GitHub
# 3. Local key exists on GitHub = mark this lesson complete and move on
#
# This function is adapted from ssh_tutr_assert_ssh_connection_is_okay()
# from .lib/ssh-connection-test.sh. It differs by allowing the lesson
# to proceed when an SSH key does not exist. In other lessons the user
# should re-create their SSH key by themselves or by re-doing this lesson.
_tutr_check_ssh_connection() {
[[ -z $DEBUG ]] && clear || set -x
ssh-keygen -F $_GH >/dev/null 2>&1 || _tutr_info _ssh_add_hostkey_msg
local msg stat ret
msg=$(ssh -o PasswordAuthentication=no -o ConnectTimeout=7 -T git@$_GH 2>&1)
stat=$?
ret=0
case $stat in
1)
# User logged in with SSH key; this lesson can be skipped
:
;;
255)
if [[ $msg == *"Permission denied"* ]]; then
# This message means the internet is working and
# the SSH key is not on GitHub.
ret=1
elif [[ $msg == *"Could not resolve hostname"* ]]; then
# DNS is down
_tutr_die _no_internet_msg "$msg"
elif [[ $msg == *"Connection timed out"* ]]; then
# Network is down
_tutr_die _no_internet_msg "$msg"
elif [[ $msg == *"Host key verification failed"* ]]; then
# Host key changed/spoofed
_tutr_die _host_key_verification_fail_msg "'$msg'"
elif [[ $msg == *"Too many authentication failures"* ]]; then
# User was prompted for password
_tutr_die _too_many_auth_failures_msg "'$msg'"
else
_tutr_die _other_problem_msg "'$msg'"
fi
;;
*)
if _tutr_ssh_key_is_present; then
_tutr_warn _ssh_key_exists_msg $REPLY
else
_tutr_die _ssh_key_is_missing_msg
fi
;;
esac
[[ -n $DEBUG ]] && set +x
return $ret
}
setup() {
source screen-size.sh 80 30
source assert-program-exists.sh
_tutr_assert_program_exists ssh-keygen
_tutr_assert_program_exists ssh
if _tutr_check_ssh_connection; then
_tutr_info _ssh_key_is_already_installed_msg
_record_completion ${_TUTR#./} lesson_complete
cleanup $_COMPLETE
exit
fi
export _BASE="$PWD"
}
prologue() {
[[ -z $DEBUG ]] && clear
echo
cat <<-PROLOGUE
$(_tutr_progress)
Shell Lesson #5: SSH Keys
In this lesson you will
* Create an SSH key with $(cmd ssh-keygen)
* Learn what an SSH key is and how to put it on GitHub
* Test that your SSH key is correctly set up with $(cmd ssh)
This lesson takes around $_DURATION minutes.
PROLOGUE
_tutr_pressenter
cat <<-:
$(cyn SSH), the $(cyn S)ecure $(cyn SH)ell, is a system for securely running commands on a
remote computer.
Most programmers know it as the tool that lets them log in to another
computer to run shell commands. This gives rise to the saying:
$(cyn '"Remote login is a lot like astral projection"')
But SSH is much more than an out-of-body experience for computers.
$(bld Any) program, not just a command shell, can be executed from a
distance. This has great implications for programmers and system
administrators, and it is something that you will do regularly on this
team once you begin using $(bld Git).
Securing this connection is of the utmost importance.
:
_tutr_pressenter
cat <<-:
$(bld "Cool story, bro. But what is an SSH key?")
An SSH key is a file on your computer that contains a really long random
number. In a moment you'll get to see what one looks like.
Your SSH key will serve as both your $(username) and your $(password) when
connecting to GitHub from the command line. This point is very
important. When you begin using Git on $(_team), your SSH key will
save you from re-typing your $(password) dozens of times each day.
Besides enabling you to be more lazy than ever, your SSH key is still
more secure than your $(password).
Sound too good to be true? Hang on tight, and I'll explain everything!
:
_tutr_pressenter
}
ssh_keygen_ff() {
if [[ ! -f "$HOME/.ssh/id_rsa" ]]; then
ssh-keygen -t rsa -b $_KEYSIZE
fi
if [[ ! -f "$HOME/.ssh/id_rsa.pub" ]]; then
ssh-keygen -y -f "$HOME/.ssh/id_rsa" > "$HOME/.ssh/id_rsa.pub"
fi
}
ssh_keygen_prologue() {
cat <<-MSG
An SSH key is generated with a program called $(cmd ssh-keygen).
You can run it like this:
$(cmd ssh-keygen -t rsa -b $_KEYSIZE)
* The $(cmd "-t rsa") option creates a key for use with the $(bld RSA)
encryption algorithm.
* $(cmd "-b $_KEYSIZE") builds the key with a $_KEYSIZE-bit random number. This
is big enough to keep the bad guys from guessing your key (for now).
MSG
_tutr_pressenter
cat <<-MSG
Before you run $(cmd ssh-keygen), I want to give you a quick heads-up.
You will be asked some questions, and you should just hit $(kbd '<ENTER>') for
each of them.
The first prompt asks $(bld where) to save your key. The default is
$(path '$HOME/.ssh/id_rsa'), and this lesson expects exactly that
location. Don't type anything else. Just press $(kbd '<ENTER>').
The second prompt asks for a $(bld passphrase). Most users $(bld leave this)
$(bld blank). You will be asked for it twice, so hit $(kbd '<ENTER>') twice.
MSG
_tutr_pressenter
cat <<-MSG
After your SSH key is created, you'll be shown its $(bld fingerprint) and
$(bld randomart) image. They look weird, and are mostly harmless, so
you can ignore them.
Run $(cmd ssh-keygen -t rsa -b $_KEYSIZE) to create your SSH key.
MSG
}
ssh_keygen_test() {
[[ -n $DEBUG ]] && echo ssh_keygen_test && _tutr_pressenter
_KEYGEN_ARG=99
if _tutr_ssh_key_is_present && [[ $REPLY == *id_rsa ]]; then return 0
elif [[ ${_CMD[0]} == ssh && ${_CMD[1]} == -keygen ]]; then return $_KEYGEN_ARG
elif [[ ${_CMD[*]} == "ssh-keygen "*"-b"*"-t"* ]]; then
_tutr_generic_test -c ssh-keygen -a "-b" -a $_KEYSIZE -a "-t" -a rsa
else
_tutr_generic_test -c ssh-keygen -a "-t" -a rsa -a "-b" -a $_KEYSIZE
fi
}
ssh_keygen_hint() {
case $1 in
$NOOP)
;;
$_KEYGEN_ARG)
cat <<-:
$(cmd "-keygen") is not an option for $(cmd ssh).
$(cmd ssh-keygen) is one word. Try again.
:
;;
*)
_tutr_generic_hint $1 ssh-keygen $_BASE
cat <<-:
Create your SSH key with $(cmd ssh-keygen -t rsa -b $_KEYSIZE).
:
;;
esac
}
ssh_keygen_epilogue() {
if [[ -n $ZSH_NAME ]]; then
emulate -L zsh
setopt ksh_arrays
fi
local rorschach=(
"a butterfly hovering above a hurricane"
"a burning fire extinguisher"
"a dragon breathing fire on a windmill"
"a sad clown juggling smaller, happier clowns"
"a sea lion playing the violin"
"a bird, a plane, or maybe Superman in flight"
"an explosion of fruit flavor"
"a jumbled assortment of letters, numbers, and symbols"
"a mythological creature, perhaps a fairy or an honest politician"
"a map of an imaginary country called 'Canada'"
)
cat <<-:
I see ${rorschach[$RANDOM % ${#rorschach[@]}]}.
What do you think it looks like?
:
_tutr_pressenter
}
chdir_to_ssh_dir_rw() {
cd
}
chdir_to_ssh_dir_ff() {
cd ~/.ssh
}
chdir_to_ssh_dir_prologue() {
cat <<-MSG
Let's navigate to the directory that contains your SSH key.
Change directories into $(path '~/.ssh').
MSG
}
chdir_to_ssh_dir_test() {
if [[ "$PWD" == "$HOME/.ssh" ]]; then return 0
else _tutr_generic_test -c cd -d "$HOME/.ssh"
fi
}
chdir_to_ssh_dir_hint() {
_tutr_generic_hint $1 "cd ~/.ssh" "$HOME/.ssh"
[[ $1 = $WRONG_PWD ]] && return
cat <<-:
$(cmd cd) into the $(path ~/.ssh) directory.
:
}
ls_ssh_dir_prologue() {
cat <<-MSG
Now take a look at the contents of this directory.
MSG
}
ls_ssh_dir_test() {
_tutr_generic_test -c ls -x -d "$HOME/.ssh"
}
ls_ssh_dir_hint() {
_tutr_generic_hint $1 ls "$HOME/.ssh"
}
ls_ssh_dir_epilogue() {
_tutr_pressenter
cat <<-:
There may be a few other files here, but I want you to focus on
these two: $(private id_rsa) and $(public id_rsa.pub).
:
_tutr_pressenter
}
view_private_key_prologue() {
cat <<-:
Your SSH key comes in two parts: a $(private) key and its corresponding
$(public) key. Obviously, you should strive to keep the $(private) key
a secret.
Do you want to see it? $(private id_rsa) is just a plain text file that you can
view with $(cmd cat). Take a look at it now.
:
}
view_private_key_test() {
VIEWED_WRONG_KEY=99
# Negative array subscripts only allowed in Zsh and Bash >= 4.2
# The safe way to access last element in an array ${_CMD[${#_CMD} - 1]}
if _tutr_is_viewer; then
if [[ ${_CMD[@]} != *id_rsa ]]; then
return $VIEWED_WRONG_KEY
else
_tutr_generic_test -c ${_CMD[0]} -a id_rsa -d "$HOME/.ssh"
fi
else
_tutr_generic_test -c cat -a id_rsa -d "$HOME/.ssh"
fi
}
view_private_key_hint() {
case $1 in
$NOOP)
;;
$VIEWED_WRONG_KEY)
cat <<-:
You looked at the $(public) SSH key, not the $(private) one!
$(cmd cat) $(private id_rsa), not $(public id_rsa.pub).
:
;;
*)
_tutr_generic_hint $1 cat "$HOME/.ssh"
cat <<-:
Run $(cmd cat id_rsa) to view the $(private) key.
:
;;
esac
}
view_private_key_epilogue() {
_tutr_pressenter
cat <<-MSG
Huh. So $(bld "that's") what $_KEYSIZE bits of randomness looks like.
This illustrates what I was saying about your SSH key being
more secure than your $(password).
MSG
}
pop_quiz0_prologue() {
cat <<-:
${_Y} ___ ___ _
${_Y}| _ \\___ _ __ / _ \\ _ _(_)___
${_Y}| _/ _ \\ '_ \\ | (_) | || | |_ /
${_Y}|_| \\___/ .__/ \\__\\_\\\\_,_|_/__|
${_Y} |_|${_Z}
True or False: your current $(password) is dumb and predictable, like
$(ylw_ chocolate), $(ylw_ 123456) or $(ylw_ password).
Run $(cmd true) or $(cmd false) to answer this question. Be honest.
:
}
pop_quiz0_test() {
if [[ ${_CMD[0]} == true || ${_CMD[0]} == false ]]; then return 0
else return 1
fi
}
pop_quiz0_hint() {
cat <<-:
Is your current $(password) something dumb like $(ylw_ 123456), $(ylw_ chocolate)
or $(ylw_ password)?
Run $(cmd true) or $(cmd false) to answer this question. Be honest.
:
}
pop_quiz0_epilogue() {
if [[ ${_CMD[0]} == true ]]; then
cat <<-:
Your candor does you credit.
:
else
cat <<-:
${_Y}
${_Y} . : .
${_Y} . : | : .
${_Y} . | | | ,
${_Y} \\ | | /
${_Y} . ,-'"""\`-. .
${_Y} "- /${_B} __ __ ${_Y}\\ -"
${_Y} |${_B}==| I |==${_Y}|
${_Y}- --- | ${_R}_${_B}\`--^--'${_R}_${_Y} | --- -
${_Y} |${_R}'\`. ,'\`${_Y}|
${_Y} _- \\${_R} "---" ${_Y}/ -_
${_Y} . \`-.___,-' .
${_Y} / | | \\
${_Y} .' | | | \`.
${_Y} : | :
${_Y} . : .
${_W}Hearing that made my day!${_Z}
:
fi
cat <<-:
Anyway, which do you think is harder for a hacker to guess?
Your little, itty-bitty $(password), or this magnificent SSH key?
:
_tutr_pressenter
cat <<-:
I think we both know the answer.
So, maybe you shouldn't show $(private id_rsa) to anyone else, ever.
And definitely don't put it on somebody else's computer!
If the integrity of your $(private) key is ever compromised, you should
delete it and make a new one with $(cmd ssh-keygen).
:
_tutr_pressenter
}
stow() {
This file we just viewed the contents of is the *private* key. This key
is *not* what you want to share with others. This key is how your
computer will be able to authenticate that the public key shared with
another device is *actually* a match. This is done by using a special
math encryption algorithm, the RSA encryption algorithm.
We need to be very careful with this private key, as knowledge of the
private key can be used to generate fake matching public keys. This
cannot be done the other way around. Hence why we can share the public
key but cannot share the private key.
MSG
_tutr_pressenter
}
stow() {
cat <<-MSG
The file 'id_rsa.pub' is your *public* SSH key. This file is the file
we want to share with others to authenticate a connection.
MSG
_tutr_pressenter
cat <<-MSG
When an SSH key is generated, there are two parts of this key; a
public key and a private key. The public part of the key is shared
with the device you want to connect to, and the private key stays on
your device. By sharing the public key with another device, you are
stating that it is A-Okay for your two devices to establish a secure
connection between them. You can share the public key with numerous
devices, allowing your device to establish an SSH connection with
various devices.
MSG
_tutr_pressenter
}
view_public_key_prologue() {
cat <<-MSG
Which brings us to the next file, $(public id_rsa.pub), your SSH $(public) key.
The rules for this key are the opposite of the $(private) key. You can
hand $(public id_rsa.pub) out like candy at Halloween. This is the file that you
will put on GitHub.
Wanna check it out? Go on and $(cmd cat) it.
MSG
}
view_public_key_test() {
VIEWED_WRONG_KEY=99
if _tutr_is_viewer; then
if [[ ${_CMD[@]} != *id_rsa.pub ]]; then
return $VIEWED_WRONG_KEY
else
_tutr_generic_test -c ${_CMD[0]} -a id_rsa.pub -d "$HOME/.ssh"
fi
else
_tutr_generic_test -c cat -a id_rsa.pub -d "$HOME/.ssh"
fi
}
view_public_key_hint() {
case $1 in
$NOOP)
;;
$VIEWED_WRONG_KEY)
cat <<-:
You looked at the $(private) SSH key, not the $(public) one!
$(cmd cat) $(public id_rsa.pub), not $(private id_rsa).
:
;;
*)
_tutr_generic_hint $1 cat "$HOME/.ssh"
cat <<-:
Run $(cmd cat id_rsa.pub) to view the $(public) key.
:
;;
esac
}
view_public_key_epilogue() {
cat <<-:
It's not much, but it'll do.
:
_tutr_pressenter
cat <<-:
${_R} _____ ${_G} _____
${_R} ,ad8PPPP88b, ${_G} ,d88PPPP8ba,
${_R} d8P" "Y8b, ${_G} ,d8P" "Y8b
${_R}dP' "8a ${_G} 8" \`Yd ${_Z} Your $(public) and $(private) keys fit
${_R}8( BEST SSH \\${_G} \\ )8${_Z} together like the matching halves
${_R}I8 / ${_G} / 8I ${_Z} of a friendship locket. You can
${_R} Yb, FRIENDS / ${_G}/ FOR ,dP ${_Z}give the $(public) key to any computer
${_R} "8a, \\ ${_G} \\ ,a8" ${_Z} that you want to be besties with.
${_R} "8a, \\${_G} \\ EVAH! ,a8"
${_R} "Yba / ${_G} / adP" ${_Z} Later, when you connect to that
${_R} \`Y8a / ${_G} / a8P' ${_Z} computer through SSH, both parties
${_R} \`88, \\${_G} \\ ,88' ${_Z} make sure their halves of the
${_R} "8b \\ ${_G} \\d8" ${_Z} locket match before logging you in.
${_R} "8b \\${_G} 8"
${_R} \`888${_G}
${_R} "
Because SSH keys are unique, they can
0. $(username identify) you (i.e. serve as your $(username))
1. $(password authenticate) you (i.e. act like a $(password))
:
_tutr_pressenter
cat <<-:
An important difference between $(private) and $(public) keys is that
there exists an algorithm that can derive the $(public) key from its
corresponding $(private) key, but not vice-versa. This is why it is
unsafe to share your $(private) key with anyone.
So what does it mean if an attacker ever takes control of your $(private)
key? They can impersonate you and log into any systems that have been
told to trust the corresponding $(public) key. If you ever suspect that
your $(private) key has been compromised, log on to those systems as
soon as possible and replace or remove the $(public) key.
:
_tutr_pressenter
_tutr_open $_HTTPS_GITHUB_KEYS
#|| _tutr_warn echo "Open '$_HTTPS_GITHUB_KEYS' in your web browser"
cat <<-:
I have opened a browser window to the GitHub page where you will save
your $(public) key. If you haven't already done so, you will sign up
and/or log in to GitHub now.
(If a browser window didn't pop up for you, go to
$(path $_HTTPS_GITLAB_KEYS) )
Copy the contents of $(public id_rsa.pub), beginning with $(bld ssh-rsa)
(here it is again):
$(cat "$HOME/.ssh/id_rsa.pub")
...and paste this into the $(bld Key) box on this page. Click $(bld Add Key) to save.
The button will be disabled if there is something wrong with your key.
Be sure to leave off the "$(grn Tutor):" text at the beginning, as well as any
extra spaces.
It's that easy!
:
_tutr_pressenter
}
put_key_on_github_pre() {
_FAILS=0
}
put_key_on_github_prologue() {
cat <<-:
Now that your $(public) key is on GitHub, you will run a command to make
sure it works. You'll either get the $(cyn Good News) or the $(red Bad News).
$(cyn Good news)
You'll see this message, but with your GitHub username instead of
$(bld username):
$(bld Welcome to GitHub, @username!)
$(red Bad news)
You will get this password prompt:
$(bld "git@$_GH's password:")
Just hit $(kbd Ctrl-C) to cancel it, and try again.
If this persists, contact $_EMAIL for help.
So what are you waiting for? Let's find out if your SSH key is good.
$(cmd ssh -T git@$_GH)
:
}
put_key_on_github_test() {
local pattern="^ssh -T git@$_GH$|^ssh git@$_GH -T$"
if [[ ${_CMD[@]} =~ $pattern ]] && (( $_RES == 1 )); then return 0
elif [[ ${_CMD[@]} =~ $pattern ]]; then
(( ++_FAILS ))
return $STATUS_FAIL
else _tutr_generic_test -c ssh -a -T -a git@$_GH -i
fi
}
put_key_on_github_hint() {
case $1 in
$NOOP)
;;
$STATUS_FAIL)
if (( _FAILS >= 3)); then
cat <<-:
It keeps going wrong, huh? I'm sorry that this is happening to you.
I think you should ask $_EMAIL for help now.
:
elif (( _FAILS == 2 )); then
cat <<-:
Are you sure that your key was saved on GitHub? Go back to your browser
tab and check that
0. the $(bld Key) field contains your $(public) key
1. and the $(bld Add Key) button was clicked
If it helps, here is your $(public) key again:
$(cat "$HOME/.ssh/id_rsa.pub")
:
elif (( _FAILS == 1 )); then
cat <<-:
Oof, that didn't quite work, did it?
Try it again. Maybe you'll have better luck this time.
$(cmd ssh -T git@$_GH)
:
fi
;;
*)
_tutr_generic_hint $1 ssh "$HOME/.ssh"
cat <<-:
Run $(cmd cat id_rsa.pub) if you need to see your public key again.
After you've saved your public key on GitHub, run
$(cmd ssh -T git@$_GH)
as a test.
:
;;
esac
}
put_key_on_github_epilogue() {
cat <<-:
Isn't that something? You told $(cmd ssh) to log in as
$(username git)@$_GH, but it still recognized you by your
actual username. $(bld And) it didn't ask for a $(password)!
SSH keys: $(username identification) and $(password authentication) in one!
:
_tutr_pressenter
cat <<-:
Now, all of this business with $(cmd ssh-keygen) and putting keys on GitHub
needs to be repeated with $(bld every) different computer that you want to
use $(bld Git) on. It is better to think of your $(private) key as
identifying this $(bld device) instead of yourself. It is normal to have
many different $(public) keys on your GitHub account; as you have seen,
they are really easy to make.
Come back to this lesson any time you need to brush up on $(cmd ssh-keygen).
:
_tutr_pressenter
}
epilogue() {
cat <<-EPILOGUE
With an SSH key on GitHub, you are ready to learn the best thing to
happen to programmers since multi-user time-sharing operating systems
came along: $(bld Git).
In this lesson you learned how to
* Create an SSH key with $(cmd ssh-keygen)
* Learn what an SSH key is and how to put it on GitHub
* Test that your SSH key is correctly set up with $(cmd ssh)
$(blk ASCII art credit: Philip Kaulfuss)
EPILOGUE
_tutr_pressenter
}
cleanup() {
[[ -n $DEBUG ]] && _tutr_warn echo "cleanup(): 1 is $1"
_tutr_lesson_complete_msg $1
return $1
}
source main.sh && _tutr_begin \
ssh_keygen \
chdir_to_ssh_dir \
ls_ssh_dir \
view_private_key \
pop_quiz0 \
view_public_key \
put_key_on_github
# vim: set filetype=sh noexpandtab tabstop=4 shiftwidth=4 textwidth=76 colorcolumn=76: