-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathKodeKloud Cheatsheet SysAdmin Task Commands.txt
More file actions
2524 lines (1978 loc) · 130 KB
/
KodeKloud Cheatsheet SysAdmin Task Commands.txt
File metadata and controls
2524 lines (1978 loc) · 130 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
Task 1 : 27/Dec/2021
Linux TimeZones Setting :
sudo timedatectl set-timezone <timezone>
--------------------------------------------------------------------------------------------------------------------------------------------
Task 2 : 28/Dec/2021
Linux File Permissions :
sudo chmod 755 <filename>
--------------------------------------------------------------------------------------------------------------------------------------------
Task 3 : 29/Dec/2021
Create a Linux User with non-interactive shell:
sudo useradd <username> -s /sbin/nologin
--------------------------------------------------------------------------------------------------------------------------------------------
Task 4 : 30/Dec/2021
Linux Run Levels :
sudo systemctl get-default
sudo systemctl list-units --type=target --all
sudo systemctl set-default graphical.target
sudo systemctl get-default
--------------------------------------------------------------------------------------------------------------------------------------------
Task 5 : 31/Dec/2021
Linux Postfix Troubleshooting:
ssh groot@stmail01
sudo systemctl status postfix.service -l
<Error : Dec 31 15:14:56 stmail01.stratos.xfusioncorp.com postfix[571]: fatal: parameter inet_interfaces: no local interface found for ::1>
<Change inet_interfaces in /etc/postfix/main.cf>
sudo vi /etc/postfix/main.cf
<comment the line inet_interfaces=localhost>
#inet_interfaces = localhost
cat /etc/postfix/main.cf |grep inet
sudo systemctl restart postfix.service
sudo systemctl status postfix.service
telnet stmail01 25
--------------------------------------------------------------------------------------------------------------------------------------------
Task 6 : 1/Jan/2022 : Failed <Wrong Answer >
Linux String Substitute (sed)
sed -e '/software/d' /home/BSD.txt > /home/BSD_DELETE.txt
sed -e 's/or/for/g' /home/BSD.txt > /home/BSD_REPLACE.txt <Wrong Answer>
sed -e 's/\bor\b/for/g' /home/BSD.txt > /home/BSD_REPLACE.txt <Possible Right Answer><Set Word Boundaries>
--------------------------------------------------------------------------------------------------------------------------------------------
Task 7 : 2/Jan/2022
Linux Banner
For Application Servers :
[jump server] thor@jump_host$ scp -r /home/thornautilus_banner tony@stapp01:/tmp
ssh tony@stapp01
cd /tmp
ls -ahl nautilus_banner
sudo mv nautillus_banner /etc/motd
cat /etc/motd
exit
ssh tony@stapp01
For DB Server
[jump server] thor@jump_host$ scp -r nautilus_banner peter@stdb01:/tmp
scp command not found
ssh peter@stdb01
sudo yum install openssh-clients -y
exit
[jump server] thor@jump_host$ scp -r nautilus_banner peter@stdb01:/tmp
ssh peter@stdb01
cd /tmp
ls -ahl nautilus_banner
sudo mv nautillus_banner /etc/motd
cat /etc/motd
exit
ssh peter@stdb01
--------------------------------------------------------------------------------------------------------------------------------------------
Task 8 : 4/Jan/2022
Linux User Expiry
ssh tony@stapp01
sudo chage -l kareem
sudo useradd kareem
sudo chage -E 2021-04-15 kareem
sudo chage -l kareem
--------------------------------------------------------------------------------------------------------------------------------------------
Task 9 : 5/Jan/2022
Linux Remote Copy
[jump server] thor@jump_host$ cd /tmp
[jump server] thor@jump_host$ ls -ahl
[jump server] thor@jump_host$ scp -r nautilus.txt.gpg steve@stapp02:/home/webapp
ssh steve@stapp02
cd /home/webapp
ls -ahl
--------------------------------------------------------------------------------------------------------------------------------------------
Task 10: 6/Jan/2022
Linux Services
ssh tony@stapp01
sudo yum install -y nscd
sudo systemctl status nscd
sudo systemctl enable nscd
sudo systemctl start nscd
sudo systemctl status nscd
--------------------------------------------------------------------------------------------------------------------------------------------
Task 11 : 8/Jan/2022
Linux Collaborative Directories
ssh banner@stapp03
sudo mkdir -p /dbadmin/data
ls -ahl
sudo chown -R root:dbadmin /dbadmin/data
ls -ahl
sudo chmod -R 2770 /dbadmin/data
ls -ahl
--------------------------------------------------------------------------------------------------------------------------------------------
Task 12 : 9/Jan/2022
Linux SSH Authentication
The system admins team of xFusionCorp Industries has set up some scripts on jump host that run on regular intervals and perform operations on all app servers in Stratos Datacenter. To make these scripts work properly we need to make sure the thor user on jump host has password-less SSH access to all app servers through their respective sudo users (i.e tony for app server 1). Based on the requirements, perform the following:
Set up a password-less authentication from user thor on jump host to all app servers through their respective sudo users.
thor@jump_host ~$ whoami
thor
thor@jump_host ~$ pwd
/home/thor
thor@jump_host ~$ ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/thor/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/thor/.ssh/id_rsa.
Your public key has been saved in /home/thor/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:9pITPWNRkGl0+WcN51jIU0t+uZ7oMfHpx2XHAbR+VDQ thor@jump_host.stratos.xfusioncorp.com
The key's randomart image is:
+---[RSA 2048]----+
| .o+++ E+|
| +o..O B|
| .. o.%o|
| . .. +.B|
| S = o *.|
| . = o * B|
| + . + Bo|
| o . + o|
| . ..|
+----[SHA256]-----+
thor@jump_host ~$ ssh-copy-id tony@stapp01
/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/home/thor/.ssh/id_rsa.pub"
The authenticity of host 'stapp01 (172.16.238.10)' can't be established.
ECDSA key fingerprint is SHA256:Fyn/TgfF2RmCbf4pEiPUgikWi31NZakcgwHoiGyecnA.
ECDSA key fingerprint is MD5:28:84:b8:ab:8a:09:e8:fb:60:2b:74:c3:02:c8:41:fc.
Are you sure you want to continue connecting (yes/no)? yes
/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
tony@stapp01's password:
Number of key(s) added: 1
Now try logging into the machine, with: "ssh 'tony@stapp01'"
and check to make sure that only the key(s) you wanted were added.
thor@jump_host ~$ ssh tony@stapp01
[tony@stapp01 ~]$
[tony@stapp01 ~]$
[tony@stapp01 ~]$ exit
logout
Connection to stapp01 closed.
thor@jump_host ~$ ssh-copy-id steve@stapp02
/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/home/thor/.ssh/id_rsa.pub"
The authenticity of host 'stapp02 (172.16.238.11)' can't be established.
ECDSA key fingerprint is SHA256:9T2mbngN2wQib3n0DphD8fyv7kY+CPcni8A1qHXbfzo.
ECDSA key fingerprint is MD5:94:dd:44:9b:5d:0b:06:72:12:26:e6:93:ad:fd:86:60.
Are you sure you want to continue connecting (yes/no)? yes
/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
steve@stapp02's password:
Number of key(s) added: 1
Now try logging into the machine, with: "ssh 'steve@stapp02'"
and check to make sure that only the key(s) you wanted were added.
thor@jump_host ~$ ssh steve@stapp02
[steve@stapp02 ~]$
[steve@stapp02 ~]$
[steve@stapp02 ~]$ exit
logout
Connection to stapp02 closed.
thor@jump_host ~$
thor@jump_host ~$ ssh-copy-id banner@stapp03
/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/home/thor/.ssh/id_rsa.pub"
The authenticity of host 'stapp03 (172.16.238.12)' can't be established.
ECDSA key fingerprint is SHA256:IgPqsR2FIyZ4mx1joA2B31QtOn+Vu7IlP/XbTorcM3Q.
ECDSA key fingerprint is MD5:dc:76:5c:62:3c:0c:28:bf:94:ba:cc:cb:82:bf:e7:2f.
Are you sure you want to continue connecting (yes/no)? yes
/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
banner@stapp03's password:
Number of key(s) added: 1
Now try logging into the machine, with: "ssh 'banner@stapp03'"
and check to make sure that only the key(s) you wanted were added.
thor@jump_host ~$ ssh banner@stapp03
[banner@stapp03 ~]$
[banner@stapp03 ~]$
[banner@stapp03 ~]$ exit
logout
Connection to stapp03 closed.
thor@jump_host ~$
--------------------------------------------------------------------------------------------------------------------------------------------
Task 13 : 10/Jan/2022
Linux String Substitute
The backup server in the Stratos DC contains several template XML files used by the Nautilus application. However, these template XML files must be populated with valid data before they can be used. One of the daily tasks of a system admin working in the xFusionCorp industries is to apply string and file manipulation commands!
Replace all occurances of the string Sample to Echo-Location on the XML file /root/nautilus.xml located in the backup server.
ssh clint@stbkp01
sudo su -
cd /root
cat nautilus.xml |grep 'Sample'|wc -l
sed -i 's/\bSample\b/Echo-Location/g' nautilus.xml
cat nautilus.xml |grep 'Sample'|wc -l
cat nautilus.xml |grep 'Echo-Location'|wc -l
--------------------------------------------------------------------------------------------------------------------------------------------
Task 14 : 11/Jan/2022
Create a Cron Job
The Nautilus system admins team has prepared scripts to automate several day-to-day tasks. They want them to be deployed on all app servers in Stratos DC on a set schedule. Before that they need to test similar functionality with a sample cron job. Therefore, perform the steps below:
a. Install cronie package on all Nautilus app servers and start crond service.
b. Add a cron */5 * * * * echo hello > /tmp/cron_text for root user.
ssh tony@stapp01
$ sudo su -
# yum install cronie -y
# systemctl start crond.service
# systemctl status crond.service
# systemctl enable crond.service
# crontab -e
*/5 * * * * echo hello > /tmp/cron_text
#crontab -l
--------------------------------------------------------------------------------------------------------------------------------------------
Task 15 : 13/Jan/2022
Linux User Files
Copy user files (not directories) for user ravi from /home/userdata to /ecommerce with directory structure in place
ssh tony@stapp01
$ sudo su -
# cd /home/userdata
# find /home/usersdata/ -type f -user ravi|wc -l
# find /home/usersdata/ -type f -user ravi -exec cp --parents {} /ecommerce \;
# cd /ecommerce
# ls -ahl
# cd /ecommerce/home/userdata
# ls -ahl
--------------------------------------------------------------------------------------------------------------------------------------------
Task 16 : 14/Jan/2022
Disable Root Login
After doing some security audits of servers, xFusionCorp Industries security team has implemented some new security policies. One of them is to disable direct root login through SSH.
Disable direct SSH root login on all app servers in Stratos Datacenter.
ssh tony@stapp01
# sudo su -
# systemctl status sshd.service
# vi /etc/ssh/sshd_config
PermitRootLogin no
# cat /etc/ssh/sshd_config|grep Permit
# systemctl restart sshd.service
# systemctl status sshd.service
--------------------------------------------------------------------------------------------------------------------------------------------
Task 17 : 16/Jan/2022
Selinux Installation
The xFusionCorp Industries security team recently did a security audit of their infrastructure and came up with ideas to improve the application and server security. They decided to use SElinux for an additional security layer. They are still planning how they will implement it; however, they have decided to start testing with app servers, so based on the recommendations they have the following requirements:
Install the required packages of SElinux on App server 3 in Stratos Datacenter and disable it permanently for now; it will be enabled after making some required configuration changes on this host. Don't worry about rebooting the server as there is already a reboot scheduled for tonight's maintenance window. Also ignore the status of SElinux command line right now; the final status after reboot should be disabled.
ssh banner@stapp03
# sudo su -
# yum install -y selinux*
## sestatus
SELinux status: disabled
#cat /etc/selinux/config
#vi /etc/selinux/config
SELINUX=disabled
#cat /etc/selinux/config
--------------------------------------------------------------------------------------------------------------------------------------------
Task 18 : 17/Jan/2022
DNS Troubleshooting
The system admins team of xFusionCorp Industries has noticed intermittent issues with DNS resolution in several apps . App Server 2 in Stratos Datacenter is having some DNS resolution issues, so we want to add some additional DNS nameservers on this server.
As a temporary fix we have decided to go with Google public DNS (ipv4). Please make appropriate changes on this server.
ssh steve@stapp02
sudo vi /etc/resolv.conf
nameserver 8.8.8.8
nameserver 8.8.4.4
cat /etc/resolv.conf
search stratos.xfusioncorp.com
nameserver 8.8.8.8
nameserver 8.8.4.4
nameserver 127.0.0.11
options ndots:0
--------------------------------------------------------------------------------------------------------------------------------------------
Task 19 : 18/Jan/2022
Linux User Without Home
The system admins team of xFusionCorp Industries has set up a new tool on all app servers, as they have a requirement to create a service user account that will be used by that tool. They are finished with all apps except for App Server 3 in Stratos Datacenter.
Create a user named yousuf in App Server 3 without a home directory.
ssh banner@stapp03
sudo su -
#id yousuf
#useradd -M yousuf
#cat /etc/passwd|grep yousuf
yousuf:x:1002:1002::/home/yousuf:/bin/bash
#id yousuf
uid=1002(yousuf) gid=1002(yousuf) groups=1002(yousuf)
# cat /etc/passwd|grep yousuf
yousuf:x:1002:1002::/home/yousuf:/bin/bash
# ls /home/yousuf
ls: cannot access /home/yousuf: No such file or directory
--------------------------------------------------------------------------------------------------------------------------------------------
Task 20 : 20/Jan/2022
Linux NTP Setup
The system admin team of xFusionCorp Industries has noticed an issue with some servers in Stratos Datacenter where some of the servers are not in sync w.r.t time. Because of this, several application functionalities have been impacted. To fix this issue the team has started using common/standard NTP servers. They are finished with most of the servers except App Server 3. Therefore, perform the following tasks on this server:
Install and configure NTP server on App Server 3.
Add NTP server 1.south-america.pool.ntp.org in NTP configuration on App Server 3.
Please do not try to start/restart/stop ntp service, as we already have a restart for this service scheduled for tonight and we don't want these changes to be applied right now.
ssh banner@stapp03
sudo yum install -y ntp*
sudo vi /etc/ntp.conf
server 1.south-america.pool.ntp.org iburst
cat /etc/ntp.conf|grep iburst
--------------------------------------------------------------------------------------------------------------------------------------------
Task 21 : 21/Jan/2022
MariaDB Troubleshooting
There is a critical issue going on with the Nautilus application in Stratos DC. The production support team identified that the application is unable to connect to the database. After digging into the issue, the team found that mariadb service is down on the database server.
Look into the issue and fix the same.
ssh peter@stdb01
systemctl status mariadb.service
● mariadb.service - MariaDB database server
Loaded: loaded (/usr/lib/systemd/system/mariadb.service; disabled; vendor preset: disabled)
Active: inactive (dead)
sudo systemctl start mariadb.service
We trust you have received the usual lecture from the local System
Administrator. It usually boils down to these three things:
#1) Respect the privacy of others.
#2) Think before you type.
#3) With great power comes great responsibility.
[sudo] password for peter:
Job for mariadb.service failed because the control process exited with error code. See "systemctl status mariadb.service" and "journalctl -xe" for details.
sudo systemctl status mariadb.service -l
● mariadb.service - MariaDB database server
Loaded: loaded (/usr/lib/systemd/system/mariadb.service; disabled; vendor preset: disabled)
Active: failed (Result: exit-code) since Fri 2022-01-21 08:34:50 UTC; 47s ago
Process: 560 ExecStartPre=/usr/libexec/mariadb-prepare-db-dir %n (code=exited, status=1/FAILURE)
Jan 21 08:34:50 stdb01.stratos.xfusioncorp.com mariadb-prepare-db-dir[560]: Database MariaDB is not initialized, but the directory /var/lib/mysql is not empty, so initialization cannot be done.
Jan 21 08:34:50 stdb01.stratos.xfusioncorp.com systemd[1]: Child 560 belongs to mariadb.service
Jan 21 08:34:50 stdb01.stratos.xfusioncorp.com systemd[1]: mariadb.service: control process exited, code=exited status=1
Jan 21 08:34:50 stdb01.stratos.xfusioncorp.com systemd[1]: mariadb.service got final SIGCHLD for state start-pre
Jan 21 08:34:50 stdb01.stratos.xfusioncorp.com systemd[1]: mariadb.service changed start-pre -> failed
Jan 21 08:34:50 stdb01.stratos.xfusioncorp.com systemd[1]: Job mariadb.service/start finished, result=failed
Jan 21 08:34:50 stdb01.stratos.xfusioncorp.com systemd[1]: Failed to start MariaDB database server.
Jan 21 08:34:50 stdb01.stratos.xfusioncorp.com systemd[1]: Unit mariadb.service entered failed state.
Jan 21 08:34:50 stdb01.stratos.xfusioncorp.com systemd[1]: mariadb.service failed.
Jan 21 08:34:50 stdb01.stratos.xfusioncorp.com systemd[1]: mariadb.service: cgroup is empty
cd /var/lib/
ls -ahl
total 68K
drwxr-xr-x 1 root root 4.0K Jan 21 08:33 .
drwxr-xr-x 1 root root 4.0K Jan 21 08:33 ..
drwxr-xr-x 1 root root 4.0K Mar 27 2021 alternatives
drwxr-xr-x 1 root root 4.0K Mar 14 2019 dbus
drwxr-xr-x 1 root root 4.0K Apr 11 2018 games
drwxr-xr-x 1 root root 4.0K Nov 2 2018 initramfs
drwx------ 1 root root 4.0K Aug 1 2019 machines
drwxr-xr-x 1 root root 4.0K Apr 11 2018 misc
drwxr-xr-x 2 mysql mysql 4.0K Oct 1 2020 mysqld
drwxr-xr-x 1 root root 4.0K Jan 21 08:33 rpm
drwxr-xr-x 1 root root 4.0K Apr 11 2018 rpm-state
drwxr-xr-x 1 root root 4.0K Oct 15 2019 stateless
drwxr-xr-x 1 root root 4.0K Aug 1 2019 systemd
drwxr-xr-x 1 root root 4.0K Mar 27 2021 yum
sudo mv ./mysqld/ ./mysql
ls -ahl
total 68K
drwxr-xr-x 1 root root 4.0K Jan 21 08:36 .
drwxr-xr-x 1 root root 4.0K Jan 21 08:33 ..
drwxr-xr-x 1 root root 4.0K Mar 27 2021 alternatives
drwxr-xr-x 1 root root 4.0K Mar 14 2019 dbus
drwxr-xr-x 1 root root 4.0K Apr 11 2018 games
drwxr-xr-x 1 root root 4.0K Nov 2 2018 initramfs
drwx------ 1 root root 4.0K Aug 1 2019 machines
drwxr-xr-x 1 root root 4.0K Apr 11 2018 misc
drwxr-xr-x 2 mysql mysql 4.0K Oct 1 2020 mysql
drwxr-xr-x 1 root root 4.0K Jan 21 08:33 rpm
drwxr-xr-x 1 root root 4.0K Apr 11 2018 rpm-state
drwxr-xr-x 1 root root 4.0K Oct 15 2019 stateless
drwxr-xr-x 1 root root 4.0K Aug 1 2019 systemd
drwxr-xr-x 1 root root 4.0K Mar 27 2021 yum
sudo systemctl start mariadb.service
sudo systemctl status mariadb.service -l
● mariadb.service - MariaDB database server
Loaded: loaded (/usr/lib/systemd/system/mariadb.service; disabled; vendor preset: disabled)
Active: active (running) since Fri 2022-01-21 08:36:36 UTC; 6s ago
Process: 726 ExecStartPost=/usr/libexec/mariadb-wait-ready $MAINPID (code=exited, status=0/SUCCESS)
Process: 644 ExecStartPre=/usr/libexec/mariadb-prepare-db-dir %n (code=exited, status=0/SUCCESS)
Main PID: 725 (mysqld_safe)
CGroup: /docker/7f68724b430981fe5a30e09857b4ab85ca0ef61407110b8195d31483d08b2c1e/system.slice/mariadb.service
├─725 /bin/sh /usr/bin/mysqld_safe --basedir=/usr
└─889 /usr/libexec/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib64/mysql/plugin --log-error=/var/log/mariadb/mariadb.log --pid-file=/var/run/mariadb/mariadb.pid --socket=/var/lib/mysql/mysql.sock
Jan 21 08:36:34 stdb01.stratos.xfusioncorp.com systemd[725]: Executing: /usr/bin/mysqld_safe --basedir=/usr
Jan 21 08:36:34 stdb01.stratos.xfusioncorp.com systemd[726]: Executing: /usr/libexec/mariadb-wait-ready 725
Jan 21 08:36:34 stdb01.stratos.xfusioncorp.com mysqld_safe[725]: 220121 08:36:34 mysqld_safe Logging to '/var/log/mariadb/mariadb.log'.
Jan 21 08:36:34 stdb01.stratos.xfusioncorp.com mysqld_safe[725]: 220121 08:36:34 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
Jan 21 08:36:36 stdb01.stratos.xfusioncorp.com systemd[1]: Child 726 belongs to mariadb.service
Jan 21 08:36:36 stdb01.stratos.xfusioncorp.com systemd[1]: mariadb.service: control process exited, code=exited status=0
Jan 21 08:36:36 stdb01.stratos.xfusioncorp.com systemd[1]: mariadb.service got final SIGCHLD for state start-post
Jan 21 08:36:36 stdb01.stratos.xfusioncorp.com systemd[1]: mariadb.service changed start-post -> running
Jan 21 08:36:36 stdb01.stratos.xfusioncorp.com systemd[1]: Job mariadb.service/start finished, result=done
Jan 21 08:36:36 stdb01.stratos.xfusioncorp.com systemd[1]: Started MariaDB database server.
--------------------------------------------------------------------------------------------------------------------------------------------
Task 22 : 22/Jan/2022
Linux Configure sudo
We have some users on all app servers in Stratos Datacenter. Some of them have been assigned some new roles and responsibilities, therefore their users need to be upgraded with sudo access so that they can perform admin level tasks.
a. Provide sudo access to user jim on all app servers.
b. Make sure you have set up password-less sudo for the user.
ssh banner@stapp03
id jim
sudo cat /etc/sudoers|grep jim
sudo visudo <Edit sudoers file>
jim ALL=(ALL) NOPASSWD:ALL <Insert this line at end of file>
sudo cat /etc/sudoers|grep jim
jim ALL=(ALL) NOPASSWD:ALL
sudo su - jim <Password less login to jim shell>
--------------------------------------------------------------------------------------------------------------------------------------------
Task 23 : 23/Jan/2022
Linux GPG Encryption
We have confidential data that needs to be transferred to a remote location, so we need to encrypt that data.We also need to decrypt data we received from a remote location in order to understand its content.
On storage server in Stratos Datacenter we have private and public keys stored /home/*_key.asc. Use those keys to perform the following actions.
Encrypt /home/encrypt_me.txt to /home/encrypted_me.asc.
Decrypt /home/decrypt_me.asc to /home/decrypted_me.txt. (Passphrase for decryption and encryption is kodekloud).
1. Login on storage server & switch to root user
ssh natasha@ststor01
sudo su -
2. All file in /home
# cd /home/
# ls -ahl
total 32K
drwxr-xr-x 1 root root 4.0K Jan 23 15:21 .
drwxr-xr-x 1 root root 4.0K Jan 23 15:20 ..
drwx------ 1 ansible ansible 4.0K Oct 15 2019 ansible
-rw-r--r-- 1 root root 155 Jan 23 15:16 decrypt_me.asc
-rw-r--r-- 1 root root 99 Jan 23 15:21 encrypt_me.txt
drwx------ 1 natasha natasha 4.0K Jan 12 2020 natasha
-rw-r--r-- 1 root root 3.6K Jan 23 15:21 private_key.asc
-rw-r--r-- 1 root root 1.7K Jan 23 15:21 public_key.asc
3. Import gpg Public and Private keys
# gpg --import public_key.asc
gpg: directory `/root/.gnupg' created
gpg: new configuration file `/root/.gnupg/gpg.conf' created
gpg: WARNING: options in `/root/.gnupg/gpg.conf' are not yet active during this run
gpg: keyring `/root/.gnupg/secring.gpg' created
gpg: keyring `/root/.gnupg/pubring.gpg' created
gpg: /root/.gnupg/trustdb.gpg: trustdb created
gpg: key CCE3AF51: public key "kodekloud <kodekloud@kodekloud.com>" imported
gpg: Total number processed: 1
gpg: imported: 1 (RSA: 1)
# gpg --import private_key.asc
gpg: key CCE3AF51: secret key imported
gpg: key CCE3AF51: "kodekloud <kodekloud@kodekloud.com>" not changed
gpg: Total number processed: 1
gpg: unchanged: 1
gpg: secret keys read: 1
gpg: secret keys imported: 1
4. Kindly verify keys are imported successfully
# gpg --list-keys
/root/.gnupg/pubring.gpg
------------------------
pub 2048R/CCE3AF51 2020-01-19
uid kodekloud <kodekloud@kodekloud.com>
sub 2048R/865C070D 2020-01-19
# gpg --list-secret-keys
/root/.gnupg/secring.gpg
------------------------
sec 2048R/CCE3AF51 2020-01-19
uid kodekloud <kodekloud@kodekloud.com>
ssb 2048R/865C070D 2020-01-19
5. Encrypt txt file to asc
# gpg --encrypt -r kodekloud@kodekloud.com --armor < encrypt_me.txt -o encrypted_me.asc
gpg: 865C070D: There is no assurance this key belongs to the named user
pub 2048R/865C070D 2020-01-19 kodekloud <kodekloud@kodekloud.com>
Primary key fingerprint: FEA8 5011 C456 B5E9 AE5A 516F 8F17 F26E CCE3 AF51
Subkey fingerprint: 7B4B 5CFC 5E4F B4B6 EEC0 83E5 DD6B 8506 865C 070D
It is NOT certain that the key belongs to the person named
in the user ID. If you *really* know what you are doing,
you may answer the next question with yes.
Use this key anyway? (y/N) y
6. Will decrypt the file asc in to txt using passphrase
# gpg --decrypt decrypt_me.asc > decrypted_me.txt
gpg: AES encrypted data
gpg: encrypted with 1 passphrase
7. check the file list in /home
# ls -ahl
total 40K
drwxr-xr-x 1 root root 4.0K Jan 23 15:25 .
drwxr-xr-x 1 root root 4.0K Jan 23 15:20 ..
drwx------ 1 ansible ansible 4.0K Oct 15 2019 ansible
-rw-r--r-- 1 root root 80 Jan 23 15:25 decrypted_me.txt
-rw-r--r-- 1 root root 155 Jan 23 15:16 decrypt_me.asc
-rw-r--r-- 1 root root 669 Jan 23 15:25 encrypted_me.asc
-rw-r--r-- 1 root root 99 Jan 23 15:21 encrypt_me.txt
drwx------ 1 natasha natasha 4.0K Jan 12 2020 natasha
-rw-r--r-- 1 root root 3.6K Jan 23 15:21 private_key.asc
-rw-r--r-- 1 root root 1.7K Jan 23 15:21 public_key.asc
8. check the output of encrypted and decrypted files
# cat decrypted_me.txt
Welcome to xFusionCorp Industries. This is KodeKloud System Administration Lab
# cat decrypt_me.asc
'h'ҊOoD+)δ1RK*PH
L1!f 21 ԎZDvpFBCV(\59.9Ӫ%Rv
# cat encrypt_me.txt
My name is "My Name"
My credit card number is 1234-5678-9012-3456
The password for my phone is 42
# cat encrypted_me.asc
-----BEGIN PGP MESSAGE-----
Version: GnuPG v2.0.22 (GNU/Linux)
hQEMA91rhQaGXAcNAQf/Shhnmvp1iMsPvS30d8tBImtVQ5z+0CpHImJoIuOLJx8w
akRvruFHX7pV0qgU4kNO0pfsmojgF8R7mlaHE9vHE9hKOYTfnHMhcm0K1bEPCY/c
UvaRpTvB+7aTtGIcIqB8BLi9lmymcIR4rMtSFe/+sHo/2m4brttnu3pj4PisMC3m
r7/z/KsyxCPHiOgcHZaz/gVcCHYCWSWI8qv5mV+aSU6kE5WULx9QsQi/kQTtMvBy
flgsTvGL8h3PPzPhUueRrOcXrjGZ9b1M1wFa5H9JfHNMxAbYB5tBexUrSRVB41To
loCwG01eHp6Qw+3Tn7qekTSCtUJ84NhppHts2HXHVtKUAZhPj8IB8cRTDrmEsYW5
f+5uwVlZQtfN0CDua54vu4BIF2sy75FEjuq+6W4yVcsJlsk7f8A7RLO0+aaqZl30
Xwtz3LREMTAYcmuhrn1ddn4M570hQILvm+I1pvH0zgU26sguWaEUtJDN8igPOM6j
nNHbLi5M3zdkM1+C8YfOMvKXRyWWIt16nZ1FoitwbDrx4LlqIA==
=EZqC
-----END PGP MESSAGE-----
# exit
--------------------------------------------------------------------------------------------------------------------------------------------
Task 24:24/Jan/2022
Add Response Headers in Apache
We are working on hardening Apache web server on all app servers. As a part of this process we want to add some of the Apache response headers for security purpose. We are testing the settings one by one on all app servers. As per details mentioned below enable these headers for Apache:
Install httpd package on App Server 2 using yum and configure it to run on 3000 port, make sure to start its service.
Create an index.html file under Apache's default document root i.e /var/www/html and add below given content in it.
Welcome to the xFusionCorp Industries!
Configure Apache to enable below mentioned headers:
X-XSS-Protection header with value 1; mode=block
X-Frame-Options header with value SAMEORIGIN
X-Content-Type-Options header with value nosniff
Note: You can test using curl on the given app server as LBR URL will not work for this task.
1. Login to App Server 2
ssh steve@stapp02
2. Install httpd Apache web server package
sudo yum install httpd -y
3. Edit httpd configuration file, add port and header configuration changes in the end of file
sudo vi /etc/httpd/conf/httpd.conf
#Listen on Port 3000
Listen 3000
#Header Configurations
Header set X-XSS-Protection "1; mode=block"
Header always append X-Frame-Options SAMEORIGIN
Header set X-Content-Type-Options nosniff
4. check the configuartion changes
cat /etc/httpd/conf/httpd.conf |grep Listen
# Listen: Allows you to bind Apache to specific IP addresses and/or
# Change this to Listen on specific IP addresses as shown below to
#Listen 12.34.56.78:80
#Listen 80
Listen 3000
cat /etc/httpd/conf/httpd.conf |grep X
Header set X-XSS-Protection "1; mode=block"
Header always append X-Frame-Options SAMEORIGIN
Header set X-Content-Type-Options nosniff
cat /etc/httpd/conf/httpd.conf |grep Header
#Header Configurations
Header set X-XSS-Protection "1; mode=block"
Header always append X-Frame-Options SAMEORIGIN
Header set X-Content-Type-Options nosniff
5. Edit index.html file
sudo vi /var/www/html/index.html
Welcome to the xFusionCorp Industries!
ls -ahl /var/www/html
total 12K
drwxr-xr-x 2 root root 4.0K Jan 24 16:20 .
drwxr-xr-x 4 root root 4.0K Jan 24 16:16 ..
-rw-r--r-- 1 root root 69 Jan 24 16:20 index.html
6. Start Apache web server service and check status
sudo systemctl start httpd
sudo systemctl status httpd
● httpd.service - The Apache HTTP Server
Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor preset: disabled)
Active: active (running) since Mon 2022-01-24 16:25:56 UTC; 7s ago
Docs: man:httpd(8)
man:apachectl(8)
Main PID: 808 (httpd)
Status: "Processing requests..."
CGroup: /docker/86ba0bd645f0a20cf7b27e3170432749c55f5b8cc39710538ac978dc448ddb5f/system.slice/httpd.service
├─808 /usr/sbin/httpd -DFOREGROUND
├─809 /usr/sbin/httpd -DFOREGROUND
├─810 /usr/sbin/httpd -DFOREGROUND
├─811 /usr/sbin/httpd -DFOREGROUND
├─812 /usr/sbin/httpd -DFOREGROUND
└─813 /usr/sbin/httpd -DFOREGROUND
Jan 24 16:25:56 stapp02.stratos.xfusioncorp.com systemd[808]: Executing: /usr/sbin/httpd -DFOREGROUND
Jan 24 16:25:56 stapp02.stratos.xfusioncorp.com httpd[808]: AH00558: httpd: Could not reliably determine the server's fully qualifie...essage
Jan 24 16:25:56 stapp02.stratos.xfusioncorp.com systemd[1]: Got notification message for unit httpd.service
Jan 24 16:25:56 stapp02.stratos.xfusioncorp.com systemd[1]: httpd.service: Got notification message from PID 808 (READY=1, STATUS=Pr...D=808)
Jan 24 16:25:56 stapp02.stratos.xfusioncorp.com systemd[1]: httpd.service: got MAINPID=808
Jan 24 16:25:56 stapp02.stratos.xfusioncorp.com systemd[1]: httpd.service: got READY=1
Jan 24 16:25:56 stapp02.stratos.xfusioncorp.com systemd[1]: httpd.service changed start -> running
Jan 24 16:25:56 stapp02.stratos.xfusioncorp.com systemd[1]: Job httpd.service/start finished, result=done
Jan 24 16:25:56 stapp02.stratos.xfusioncorp.com systemd[1]: Started The Apache HTTP Server.
Jan 24 16:25:56 stapp02.stratos.xfusioncorp.com systemd[1]: httpd.service: got STATUS=Processing requests...
Hint: Some lines were ellipsized, use -l to show in full.
7.Validate by using curl to fetch webpage
curl http://localhost:3000
Welcome to the xFusionCorp Industries!
curl -i http://localhost:3000
HTTP/1.1 200 OK
Date: Mon, 24 Jan 2022 16:27:03 GMT
Server: Apache/2.4.6 (CentOS)
X-Frame-Options: SAMEORIGIN
Last-Modified: Mon, 24 Jan 2022 16:26:47 GMT
ETag: "27-5d6566f588809"
Accept-Ranges: bytes
Content-Length: 39
X-XSS-Protection: 1; mode=block
X-Content-Type-Options: nosniff
Content-Type: text/html; charset=UTF-8
Welcome to the xFusionCorp Industries!
--------------------------------------------------------------------------------------------------------------------------------------------
Task 25:25/Jan/2022
Linux Find Command
During a routine security audit, the team identified an issue on the Nautilus App Server. Some malicious content was identified within the website code. After digging into the issue they found that there might be more infected files. Before doing a cleanup they would like to find all similar files and copy them to a safe location for further investigation. Accomplish the task as per the following requirements:
a. On App Server 3 at location /var/www/html/news find out all files (not directories) having .php extension.
b. Copy all those files along with their parent directory structure to location /news on same server.
c. Please make sure not to copy the entire /var/www/html/news directory content.
ssh banner@stapp03
sudo find /var/www/html/news/ -type f -name '*.php'|wc -l
903
sudo find /var/www/html/news/ -type f -name '*.php' -exec cp --parents {} /news \;
sudo find /news/var/www/html/news/ -type f -name '*.php'|wc -l
903
--------------------------------------------------------------------------------------------------------------------------------------------
Task 26 : 27/Jan/2022
Setup SSL for Nginx
The system admins team of xFusionCorp Industries needs to deploy a new application on App Server 2 in Stratos Datacenter. They have some pre-requites to get ready that server for application deployment. Prepare the server as per requirements shared below:
Install and configure nginx on App Server 2.
On App Server 2 there is a self signed SSL certificate and key present at location /tmp/nautilus.crt and /tmp/nautilus.key. Move them to some appropriate location and deploy the same in Nginx.
Create an index.html file with content Welcome! under Nginx document root.
For final testing try to access the App Server 2 link (either hostname or IP) from jump host using curl command. For example curl -Ik https://<app-server-ip>/.
1. Login to app server 2
ssh steve@stapp02
2. Install epel-release repository
sudo yum install epel-release -y
3. Install nginx package
sudo yum install nginx -y
4. Edit nginx config file to include server ip (172.16.238.11) and ssl certificate and key file location
<remember to uncomment the SSL configuration part>
sudo vi /etc/nginx/nginx.conf
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name 172.16.238.11;
root /usr/share/nginx/html;
# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
error_page 404 /404.html;
location = /404.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
# Settings for a TLS enabled server.
server {
listen 443 ssl http2 default_server;
listen [::]:443 ssl http2 default_server;
server_name 172.16.238.11;
root /usr/share/nginx/html;
ssl_certificate "/etc/pki/CA/certs/nautilus.crt";
ssl_certificate_key "/etc/pki/CA/private/nautilus.key";
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 10m;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
}
5. Confirm the nginx config file changes
cat /etc/nginx/nginx.conf
6. copy the certificate and key files
sudo cp /tmp/nautilus.crt /etc/pki/CA/certs/
sudo cp /tmp/nautilus.key /etc/pki/CA/private/
7. Check index.html file and replace it with mentioned file
sudo ls -ahl /usr/share/nginx/html/
total 16
-rw-r--r-- 1 root root 3650 Jun 2 00:21 404.html
-rw-r--r-- 1 root root 3693 Jun 2 00:21 50x.html
lrwxrwxrwx 1 root root 20 Jul 25 11:56 en-US -> ../../doc/HTML/en-US
drwxr-xr-x 2 root root 4096 Jul 25 11:56 icons
lrwxrwxrwx 1 root root 18 Jul 25 11:56 img -> ../../doc/HTML/img
lrwxrwxrwx 1 root root 25 Jul 25 11:56 index.html -> ../../doc/HTML/index.html
-rw-r--r-- 1 root root 368 Jun 2 00:21 nginx-logo.png
lrwxrwxrwx 1 root root 14 Jul 25 11:56 poweredby.png -> nginx-logo.png
sudo rm /usr/share/nginx/html/index.html
sudo vi /usr/share/nginx/html/index.html
Welcome!
sudo cat /usr/share/nginx/html/index.html
Welcome!
8. Start and check status of nginx server
sudo systemctl start nginx
sudo systemctl status nginx
9. From another instance of jump server
thor@jump_host ~$ curl -Ik https://stapp02
HTTP/1.1 200 OK
Server: nginx/1.20.1
Date: Sun, 25 Jul 2021 12:32:39 GMT
Content-Type: text/html
Content-Length: 9
Last-Modified: Sun, 25 Jul 2021 12:14:24 GMT
Connection: keep-alive
ETag: "60fd55a0-9"
Accept-Ranges: bytes
--------------------------------------------------------------------------------------------------------------------------------------------
Task 27 : 28/Jan/2022
Linux Bash Scripts
The production support team of xFusionCorp Industries is working on developing some bash scripts to automate different day to day tasks. One is to create a bash script for taking websites backup. They have a static website running on App Server 1 in Stratos Datacenter, and they need to create a bash script named media_backup.sh which should accomplish the following tasks. (Also remember to place the script under /scripts directory on App Server 1)
a. Create a zip archive named xfusioncorp_media.zip of /var/www/html/media directory.
b. Save the archive in /backup/ on App Server 1. This is a temporary storage, as backups from this location will be clean on weekly basis. Therefore, we also need to save this backup archive on Nautilus Backup Server.
c. Copy the created archive to Nautilus Backup Server server in /backup/ location.
d. Please make sure script won't ask for password while copying the archive file. Additionally, the respective server user (for example, tony in case of App Server 1) must be able to run it.
1.Login to app server 1
ssh tony@stapp01
2. Create the bash script
cd /scripts/
ls -ahl
total 8.0K
drwxrwxrwx 2 root root 4.0K Jan 28 06:59 .
drwxr-xr-x 1 root root 4.0K Jan 28 06:59 ..
vi media_backup.sh
#! /bin/bash
zip -r /backup/xfusioncorp_media.zip /var/www/html/media