forked from SobhaReddy/DevOpsClassCodes
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLinux_Class.txt
More file actions
591 lines (428 loc) · 15.7 KB
/
Linux_Class.txt
File metadata and controls
591 lines (428 loc) · 15.7 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
AWS Account
===========
1.free account - 750hrs - 1 yrs
Debit/credit - 2/-rs
AWS
2. Putty software(puttygen also)
Optional - Puttygen
Linux - OS
=========
Server
Linux - command line
Linux Server
==========
Launch server
EC2 instnace/service/server
Elastic Compute cloud - EC2 - VM(Virtual Machine) server
EC2 - Instance
==============
7 steps
linux20april.pem
How to convert the privatekey
========================
puttygen - public we need private key(ppkfile)
how to connect the server
========================
linux-server(ec2-instnace) - public IP Address
21/04
=========
Linux
========
linux OS, Free open source os
Unix - paid one, os
Linux
========
CentOS -
Ubuntu
SUSE Linux
Windows
=========
what is sudo -i?
=============
Sudo(Superuser do) allows a system administrator to give certailn users(or group of user) the ability to rum domr(or all) commands as root while logging all commnads and arguments
what is Root?
=============
Primary Hierarchy root and root directory of the entire file system hirerachy
1. Each single file and directory starts from the root directory
2. Only root user has the right to write under this directory
3. /root is toot user's home directory, which is not same as /
Linux
========
FSH - File System Hierarchy
=========
The Linux FSH defines the directory structure
Folder/ Directory
pwd - present working directory
mkdir linux
ls
cd linux-demo
file -creation
================
touch file1
Note :
=====
In side directory you may have 100 files - directories are difined with "blue color"
In side file there no directories - files are defined with "white color"
Delete/Remove directory/folder
=============================
rm -rf dirname
or
rm -r firectory (type - y)
Delete/Remove files
============
rm -f filename
how to create multiple directories
=============================
mkdir d1 d2 d3
How to create parent directories
====================
To create parent directories using the mkdir command pass -p option
suppose the directory path /foo/bar/baz is to created even if /foo/bar directory is not existing
Permissions and rights
================
A linux is a Multi-user Operating system which can be accessed by many user simultaneously.
Hence this raises security conecrns as am going to restrict on the perticular user
2 levels
1. Ownership
2. Pemission
How to change the ownership for file level
========================================
The chown command change ownership of files and directories in a linux filesystem
to change the owner of a files/directory
syntax: chown <ownername>(shobha) <filename>(file.txt)
How to change the ownership for group of file
=================================
"chown" command is also used to the chnage group name of a file, like "chgrp" command
chown :shobhs file.txt
file name - file.txt
1.chown ec2-user
-rw-r--r-- 1
-rw- r-- r-- 1 (file - level)
user group others
Group:
=====
chown commands is also used to change group name of a file like, "chgrp" commands
synatx: chown <groupname> <filename>
chown :ec2-user file.txt
To recursively change ownership of directories and their contents
========================
synatx: chown -R root >filename>
mkdir test
d -rw- r-- r-- 1
directory users group others
2.chown -R root filename
-R = To recursively change ownership of directories and their contents
mkdir test
chown -R ec2-user:ec2-user test
How to chnage the Permission
========================
All file system object on Unix-like system have three main typesof permissions
read, write and execute access.
permissions are based upon 3 possible class
user, the usergroup and all system users
syntax: ls -lha
1. r: Read =4
2. w: Write =2
3. x: Execution =1
Permissions
==============
Read - r - - 4
Write - w - - 2
Execution - x - - 1
====
7
Synatx: ls -lha
Example
===========
d rwx r-x r-x
dir (user) (Group) (Others)
task:
======
setting 442(rrw) permissions for the file of file.txt(filename)
rwx r-x r-x
r r w
file.txt rrw
chmod 442 file.txt
How to change the permissions & ownership recursively
==============================
to chnage the file access permissions you need to sue the chmod command. it has -R or -recursive option thar chnage files and directories recursively
mkdir dir5
cd dir5
touch file6 file7
dir5 - rwx
d rwx r-x r-x
dir (user) (Group) (Others)
7 0 0
700 --(user)--(group)--(others)
file2 r r w
r-- r-- w--
4 4 2
chmod 442 file2
permission with dire - anusha
d(rx) user(rx) group(rx) others
5 5 5
chmod -R 555 anusha
if you want give the permissions directory level(you should not entire inside the directory)
Linux/Unix Command
=========
1. File commands
ls - directory listing/ files listing
ls -al - hidden files to be displyed
cd dir - change dir to dir
cd - change to home
rm file - delete file
rm -f filename - force remove file
rm -r dir -
rm -rf dir
cp file1 file2 - copy the file1 file2
cp -r dir1 dir2 - copy the dir1 dir2
mv file file2 - rename or move file1 dile2
touch file -
cat file - to see content inside file
more file - output the content of file
head file - output the first 10 lines of file
tail file - output the last 10 lines of file
tail -f file - output the content of files as it grows, starting with the last 10 lines
2. Process managemnet
ps - display your current active process
top - display all running process
kill pid - kill process id pid
bg - list stopped or backgroundjobs; resume a stopped job in the background
fg - bring the most recent job into foreground
fg n - bring job n into foreground
3. File Permissions
chmod octal file - chnage the permisiions of file of octal, which can be found separately for user, groups and world by adding
4 - read(r)
2 - write(w)
1 - Execution(x)
Exmaple:
-
chmod 777
chmod 755
4. SSH
ssh user@host - connect to host as user
ssh -p port uset@host - connect to host on port port as user
VIM Editor:
==========
Vim is powerfull text editor used in CLI(Command Line Interface).
Linux uses a lot of configuration files.
if you edit them and vim is a great tool do so, aletrnatively VIM is a command line editor
vim flie.txt
50 lines
50 lines
vi editor
vim editor
It has 3 modes:
----
1. Command Mode
2. Insert Mode
3. Extended Mode
Note: when you open the vim editor , it will be in the command mode by default.
Insert Mode - i
Extended mode
----
save - esc:wq!
withoutsave- esc:q!
Command Mode
+++++++++++++++++
gg - to go to the beginning of the page
Shift+g - go to the end of the page
w - to move the cursor forward, word by word
b - to move the cursor backword, word by word
nw - to move the cursor forward to n words(5W)
nb - to move the cursor backend to n words(5W)
u - to undo last change(word)
Ctrl+u - to undo previous chnages (entire line)
Ctrl+r - to redo changes
yy - to copy a line
nyy - to copy n lines (5yy or 4yy)
p - to past line below the cursor position
P - to past line above the cursor positio
dw - delete the word letter by letter(like Backspace)
x - to delete the word letter by letter( delete key)
dd - to delete entire line
ndd - to delete n no.of positions from cursor positions(5dd)
/ - To search a word in the file
Insert Mode(edit mode):
+++++++++++++++
i - To begin Insert Mode
I - To insert beginning of line
a - To Append the next word's letter
A - To append at the end of the line
o - To insert a new line below the cursor positions
O - To insert a new line Above the cursor positions
Extended Mode(colon Mode)
++++++++++++
Esc+:w - To save the changes
Esc+:q! - to quit(without save)
Esc+:wq - to save and quit
Esc+:w! - To save forcefully
Esc+:wq! - To save and quite forcefully
Esc+:x - to save and quit
Esc+:X - to give password to the file and remove password
Esc+:20(n) - to go to line no 20 or n
Esc+:se nu - to set the line numbers to the file
Esc+:se nonu - To remove the set line number
Monitoring:
+++++++++++++++++++
- when you needs to see the running process on your linux in real time, you can have top as your tool that.
- top also displayes other info besides the running process
top
tasks - shows the numbe of process and their current state
%cpu- show CPU uilizaion details, user process, system process running, system Idle cpu.
Swap Memory in Linux:
===================
Swap space in Linux is used when the amount of physical memory (RAM) is full. If the system needs more memory resources and the RAM is full, inactive pages in memory are moved to the swap space.
While swap space can help machines with a small amount of RAM, it should not be considered a replacement for more RAM.
zombie process in linux:
========================
Zombie processes in Linux are sometimes also referred to as defunct or dead processes.
They're processes that have completed their execution, but their entries are not removed from the process table.
What is buff cache Linux?
========================
buff/cache is memory used by the Linux kernel buffers and page cache.
You force clear buff/cache using the 'echo' command but observe it gradually increase again to 85% memory consumption.
Shutting down the SAP NW application and/or database server. does not show buff/cache release any memory.
PID - ProcessID
USER - Effective UserID
PR - Dynamic Prority
NI - nice Value, also known as base priority
VIRT - Vitrual size of the task. This includes size of process executable binary, the data area and all the loaded shared libraries
RES - The size of RAM Currently consumed by the task, Swapped out portion of the task is not included
SHR - Some memory ares clould be shared b/w two or more task, this fileds reflects the shared area.
S - Task status
%CPU - the %CPU time dedicated to run the task since the last top's screen update
%MEM - the %Mem of RAM currently consumed by the task
TIME + - The total CPU time and task has been used since it started "+"sign means is displayed wih hundredth of second granularity.
BY default, TIME/TIME+ desont account CPU Time used by the task's dead children
COMMAND- Showing program names.
Kill userdetails
-------------
kill -9 PID
Intracting with Top
================
M-
P-
T-
z -
k -
r-
h
How do I find zombies on Linux?
===================
Image result for zombie in linux
How to find zombie processes?
D = uninterruptible sleep.
I = idle.
R = running.
S = sleeping.
T = stopped by job control signal.
t = stopped by debugger during trace.
Z = zombie.
Ping commnad
===========
packet internet Groper
ICMP - internet Control Messages
TTL - Time To Live
ping -c2 google.com
vmstat command:
================
vmstat (virtual memory stastics)
info about block IO and CPU
Shortcut File commands
===============
wc -l : Prints the number of lines in a file.(filename)
wc -w : prints the number of words in a file.
wc -c : Displays the count of bytes in a file.
wc -m : prints the count of characters from a file.
wc -L : prints only the length of the longest line in a file.
Software Management
====================
its important role in installaling and configuring the softwares.
2 ways we can approach
1.rpm - Redhat package manager
2.yum - yellow dog update manager - (centos)
Ubuntu - apt-get
RPM:
========
RPM is a package managing system(collection of tools to manage software packages) - ex- git, maven, jenkins, python, java
RPM is powerful software mangement tools for installing, uninstall, verifying, querying and updating software packages.
RPM straight forward program to perform the above s/w management tasks.
synatx:
rpm -qa (where q stands for query, and a stands fo all)
rpm -qa python
installion syntax:
====
rpm -ivh package name
list out of package in linux server
==============
rpm -qa |grep -i python
grep - global regular expression print
yum
=====
yellow dog update manager
yum install git -y
Repo:
clean
list
Networking Commands:
======================
Linux Networking Commands
ifconfig.
ip.
traceroute.
tracepath.
ping.
netstat.
ss.
dig.
Netwprk Configuration & Trouble Shooting
-----------------------
Networking - it is a connection b/w two or more machines to communicate with each other
#/etc/sysconfig/network-scripts/
ls /etc/sysconfig/network-scripts/
cat /etc/sysconfig/network:
---------------------
is a file whiich keep the information about the hostname assigned to the system.
if you want to change the hostname permenently , you need to change the hostname in this file.
checking the IP Address
===========
ifconfig -a
DNS
----
Domain Name spacific
nslookup ipaddress/hostname
nslookup
What is the difference between sudo and su command?
===================================
The main difference between Su and Sudo is that the Su command can interchange between superuser and root user if executed without prior additional options while the Sudo command provides single root privileges.
Su demands the password of the root account while Sudo demands the password of the current user account
what is inode in linux?
=======================
What is an inode? By definition, an inode is an index node. It serves as a unique identifier for a specific piece of metadata on a given filesystem.
Each piece of metadata describes what we think of as a file. That's right, inodes operate on each filesystem, independent of the others
Why is inode used?
===================
Inodes keep track of all the files on a Linux system. Except for the file name and the actual content of the file, inodes save everything else.
It's like a file-based data structure that holds metadata about all of the files in the system.
what is softlink in linux?
======================
Soft links are similar to shortcuts, and can point to another file or directory in any file system.
Hard links are also shortcuts for files and folders, but a hard link cannot be created for a folder or file in a different file system.
These can be created in the following way on Linux and Mac operating systems.
what is hard link in linux?
=======================
Every file on the Linux filesystem starts with a single hard link. The link is between the filename and the actual data stored on the filesystem
what is hardening in linux?
========================
What is OS Hardening? Operating system (OS) hardening, a type of system hardening, is the process of implementing security measures and patching for operating systems, such as Windows, Linux, or Apple OS X, with the objective of protecting sensitive computing systems.
what is the difference between grep and find?
=====================================
The main difference between the two is that grep is used to search for a particular string in a file whereas find is used to locate files in a directory, etc. also you might want to check out the two commands by typing 'man find' and 'man grep'
what is the Linux Volumes
============================
A physical volume will be seen as /dev/sda, /dev/sdb; a physical disk that is detected by Linux.
If we have two physical disks of 1TB each, we can create a volume group of almost 2TB amongst the two. From the volume group, we can create three logical volumes each of any-size not exceeding the total volume group size
What is the use of LVM in Linux?
==============================
LVM is used for the following purposes: Creating single logical volumes of multiple physical volumes or entire hard disks (somewhat similar to RAID 0, but more similar to JBOD), allowing for dynamic volume resizing.