-
Notifications
You must be signed in to change notification settings - Fork 35
Expand file tree
/
Copy pathec2_ssh_user_guide.html
More file actions
500 lines (413 loc) Β· 15.1 KB
/
ec2_ssh_user_guide.html
File metadata and controls
500 lines (413 loc) Β· 15.1 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Adding Users via SSH on EC2</title>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
background: linear-gradient(135deg, #FF9A56 0%, #FF6A88 100%);
min-height: 100vh;
display: flex;
justify-content: center;
align-items: center;
padding: 20px;
}
.presentation {
background: white;
border-radius: 20px;
box-shadow: 0 20px 60px rgba(0,0,0,0.3);
width: 100%;
max-width: 1000px;
min-height: 550px;
padding: 50px;
position: relative;
}
.slide {
display: none;
animation: fadeIn 0.5s;
}
.slide.active {
display: block;
}
@keyframes fadeIn {
from { opacity: 0; transform: translateY(20px); }
to { opacity: 1; transform: translateY(0); }
}
h1 {
color: #FF6A88;
font-size: 2.5em;
margin-bottom: 20px;
}
h2 {
color: #FF6A88;
font-size: 2em;
margin-bottom: 20px;
}
h3 {
color: #FF9A56;
font-size: 1.4em;
margin: 20px 0 10px 0;
}
p {
font-size: 1.2em;
line-height: 1.6;
color: #333;
margin-bottom: 15px;
}
.code-box {
background: #1e1e1e;
color: #d4d4d4;
border-left: 4px solid #FF6A88;
padding: 15px;
margin: 20px 0;
font-family: 'Courier New', monospace;
font-size: 0.95em;
border-radius: 5px;
overflow-x: auto;
}
.code-box .comment {
color: #6a9955;
}
.code-box .prompt {
color: #4ec9b0;
}
.info-box {
background: #e8f5e9;
border-left: 4px solid #4caf50;
padding: 15px;
margin: 20px 0;
border-radius: 5px;
}
.warning-box {
background: #fff3cd;
border-left: 4px solid #ffc107;
padding: 15px;
margin: 20px 0;
border-radius: 5px;
}
.step-box {
background: #f0f4ff;
border-left: 4px solid #2196f3;
padding: 15px;
margin: 15px 0;
border-radius: 5px;
}
.step-number {
background: #FF6A88;
color: white;
width: 35px;
height: 35px;
border-radius: 50%;
display: inline-flex;
align-items: center;
justify-content: center;
font-weight: bold;
margin-right: 10px;
font-size: 1.2em;
}
.controls {
position: absolute;
bottom: 20px;
right: 20px;
display: flex;
gap: 10px;
}
button {
background: #FF6A88;
color: white;
border: none;
padding: 12px 24px;
border-radius: 8px;
cursor: pointer;
font-size: 1em;
transition: all 0.3s;
}
button:hover {
background: #FF9A56;
transform: translateY(-2px);
box-shadow: 0 5px 15px rgba(0,0,0,0.2);
}
button:disabled {
background: #ccc;
cursor: not-allowed;
transform: none;
}
.slide-counter {
position: absolute;
top: 20px;
right: 20px;
color: #FF6A88;
font-size: 1.1em;
font-weight: bold;
}
ul {
margin: 20px 0 20px 30px;
font-size: 1.1em;
line-height: 1.8;
}
.emoji {
font-size: 1.3em;
margin-right: 8px;
}
.method-card {
background: #f5f5f5;
padding: 20px;
border-radius: 10px;
margin: 15px 0;
border-left: 5px solid #FF6A88;
}
table {
width: 100%;
border-collapse: collapse;
margin: 20px 0;
}
th, td {
padding: 12px;
text-align: left;
border-bottom: 1px solid #ddd;
}
th {
background: #FF6A88;
color: white;
}
tr:hover {
background: #f5f5f5;
}
</style>
</head>
<body>
<div class="presentation">
<div class="slide-counter">
<span id="current">1</span> / <span id="total">9</span>
</div>
<!-- Slide 1: Title -->
<div class="slide active">
<h1>βοΈ Adding Users via SSH on EC2</h1>
<p style="font-size: 1.5em; margin-top: 40px;">A Complete Guide to User Management</p>
<div style="margin-top: 60px;">
<p><span class="emoji">π</span> Secure SSH access</p>
<p><span class="emoji">π₯</span> Multiple user management</p>
<p><span class="emoji">π</span> SSH key authentication</p>
<p><span class="emoji">β‘</span> Best practices included</p>
</div>
</div>
<!-- Slide 2: Prerequisites -->
<div class="slide">
<h2>π Prerequisites</h2>
<p>Before you start, make sure you have:</p>
<div class="step-box">
<p><span class="step-number">1</span><strong>Running EC2 Instance</strong></p>
<p style="margin-left: 45px;">Your EC2 instance should be up and running</p>
</div>
<div class="step-box">
<p><span class="step-number">2</span><strong>SSH Access</strong></p>
<p style="margin-left: 45px;">You can already connect to your EC2 instance via SSH</p>
</div>
<div class="step-box">
<p><span class="step-number">3</span><strong>Root/Sudo Privileges</strong></p>
<p style="margin-left: 45px;">You need sudo access to create users</p>
</div>
<div class="step-box">
<p><span class="step-number">4</span><strong>Key Pair (Optional)</strong></p>
<p style="margin-left: 45px;">SSH key for the new user (for key-based auth)</p>
</div>
</div>
<!-- Slide 3: Connect to EC2 -->
<div class="slide">
<h2>π Step 1: Connect to Your EC2</h2>
<h3>For Amazon Linux / Ubuntu:</h3>
<div class="code-box">
<span class="comment"># Amazon Linux</span>
ssh -i your-key.pem ec2-user@your-ec2-ip
<span class="comment"># Ubuntu</span>
ssh -i your-key.pem ubuntu@your-ec2-ip
</div>
<div class="info-box">
<p><span class="emoji">π‘</span> <strong>Tip:</strong> Replace <code>your-key.pem</code> with your actual key file name and <code>your-ec2-ip</code> with your instance's public IP or DNS.</p>
</div>
<div class="warning-box">
<p><span class="emoji">β οΈ</span> <strong>Permission Error?</strong> Run: <code>chmod 400 your-key.pem</code></p>
</div>
</div>
<!-- Slide 4: Create New User -->
<div class="slide">
<h2>π€ Step 2: Create a New User</h2>
<h3>Basic user creation:</h3>
<div class="code-box">
<span class="comment"># Create a new user named 'john'</span>
sudo adduser john
<span class="comment"># You'll be prompted to set a password and user details</span>
<span class="comment"># Press Enter to skip optional fields</span>
</div>
<h3>What happens:</h3>
<ul>
<li>Creates a new user account</li>
<li>Creates a home directory: <code>/home/john</code></li>
<li>Sets up basic user configuration</li>
<li>Prompts for password (if using password auth)</li>
</ul>
<div class="info-box">
<p><span class="emoji">π</span> <strong>Alternative:</strong> Use <code>sudo useradd john</code> for basic user creation without prompts, then set password with <code>sudo passwd john</code></p>
</div>
</div>
<!-- Slide 5: Grant Sudo Access -->
<div class="slide">
<h2>β‘ Step 3: Grant Sudo Access (Optional)</h2>
<p>If the new user needs administrative privileges:</p>
<h3>Method 1: Add to sudo group</h3>
<div class="code-box">
<span class="comment"># Amazon Linux / Ubuntu</span>
sudo usermod -aG sudo john
<span class="comment"># CentOS / RHEL</span>
sudo usermod -aG wheel john
</div>
<h3>Method 2: Edit sudoers file</h3>
<div class="code-box">
<span class="comment"># Open sudoers file safely</span>
sudo visudo
<span class="comment"># Add this line at the end:</span>
john ALL=(ALL) NOPASSWD:ALL
</div>
<div class="warning-box">
<p><span class="emoji">β οΈ</span> <strong>Warning:</strong> <code>NOPASSWD</code> allows sudo without password. Remove it if you want password prompts for sudo commands.</p>
</div>
</div>
<!-- Slide 6: Setup SSH Key Auth -->
<div class="slide">
<h2>π Step 4: Setup SSH Key Authentication</h2>
<h3>Option A: Generate key on local machine</h3>
<div class="code-box">
<span class="comment"># On your local computer</span>
ssh-keygen -t rsa -b 4096 -C "john@company.com"
<span class="comment"># Save as: john_ec2_key</span>
<span class="comment"># This creates john_ec2_key (private) and john_ec2_key.pub (public)</span>
</div>
<h3>Option B: Copy existing public key</h3>
<div class="code-box">
<span class="comment"># View your public key</span>
cat ~/.ssh/id_rsa.pub
<span class="comment"># Copy the output</span>
</div>
<div class="info-box">
<p><span class="emoji">π‘</span> <strong>Best Practice:</strong> Always use SSH key authentication instead of passwords for better security!</p>
</div>
</div>
<!-- Slide 7: Add SSH Key to User -->
<div class="slide">
<h2>π Step 5: Add SSH Key to New User</h2>
<div class="code-box">
<span class="comment"># Switch to the new user</span>
sudo su - john
<span class="comment"># Create .ssh directory</span>
mkdir -p ~/.ssh
chmod 700 ~/.ssh
<span class="comment"># Create authorized_keys file</span>
touch ~/.ssh/authorized_keys
chmod 600 ~/.ssh/authorized_keys
<span class="comment"># Add public key (paste the public key content)</span>
nano ~/.ssh/authorized_keys
<span class="comment"># Paste the public key, save and exit (Ctrl+X, Y, Enter)</span>
<span class="comment"># Exit back to your original user</span>
exit
</div>
<div class="warning-box">
<p><span class="emoji">β οΈ</span> <strong>Critical:</strong> Permissions must be exact!<br>
<code>~/.ssh</code> must be 700<br>
<code>~/.ssh/authorized_keys</code> must be 600</p>
</div>
</div>
<!-- Slide 8: Test New User -->
<div class="slide">
<h2>β
Step 6: Test the New User</h2>
<h3>From your local machine:</h3>
<div class="code-box">
<span class="comment"># Test SSH connection with the new user</span>
ssh -i john_ec2_key john@your-ec2-ip
<span class="comment"># Or if using default key</span>
ssh john@your-ec2-ip
</div>
<h3>If successful, you should see:</h3>
<div class="code-box">
<span class="prompt">john@ip-xxx-xx-xx-xx:~$</span>
</div>
<h3>Test sudo access (if granted):</h3>
<div class="code-box">
<span class="comment"># Try a sudo command</span>
sudo apt update
<span class="comment"># Should work without errors</span>
</div>
<div class="info-box">
<p><span class="emoji">π</span> <strong>Success!</strong> Your new user is ready to use!</p>
</div>
</div>
<!-- Slide 9: Security Best Practices -->
<div class="slide">
<h2>π Security Best Practices</h2>
<div class="method-card">
<h3>1. Disable Password Authentication</h3>
<div class="code-box">
sudo nano /etc/ssh/sshd_config
<span class="comment"># Set these values:</span>
PasswordAuthentication no
PubkeyAuthentication yes
<span class="comment"># Restart SSH service</span>
sudo systemctl restart sshd
</div>
</div>
<div class="method-card">
<h3>2. Disable Root Login</h3>
<div class="code-box">
<span class="comment"># In /etc/ssh/sshd_config</span>
PermitRootLogin no
</div>
</div>
<div class="method-card">
<h3>3. Other Tips</h3>
<ul>
<li>Use strong SSH keys (4096-bit RSA or Ed25519)</li>
<li>Regularly update your EC2 instance</li>
<li>Use Security Groups to restrict SSH access to specific IPs</li>
<li>Enable AWS CloudTrail for auditing</li>
<li>Consider using AWS Systems Manager Session Manager</li>
</ul>
</div>
</div>
<!-- Navigation Controls -->
<div class="controls">
<button id="prevBtn" onclick="changeSlide(-1)">β Previous</button>
<button id="nextBtn" onclick="changeSlide(1)">Next β</button>
</div>
</div>
<script>
let currentSlide = 0;
const slides = document.querySelectorAll('.slide');
const totalSlides = slides.length;
document.getElementById('total').textContent = totalSlides;
function showSlide(n) {
slides.forEach(slide => slide.classList.remove('active'));
if (n >= totalSlides) currentSlide = totalSlides - 1;
if (n < 0) currentSlide = 0;
slides[currentSlide].classList.add('active');
document.getElementById('current').textContent = currentSlide + 1;
document.getElementById('prevBtn').disabled = currentSlide === 0;
document.getElementById('nextBtn').disabled = currentSlide === totalSlides - 1;
}
function changeSlide(direction) {
currentSlide += direction;
showSlide(currentSlide);
}
document.addEventListener('keydown', (e) => {
if (e.key === 'ArrowLeft') changeSlide(-1);
if (e.key === 'ArrowRight') changeSlide(1);
});
showSlide(0);
</script>
</body>
</html>